Purpose
This function prints a JSON value in a formatted way. It is similar to PHP.
Syntax
JSON_PRETTY(json_val)
Considerations
The json_val parameter must be a JSON value or a valid string representation of a JSON value. Irrelevant spaces and line breaks in this value do not affect the output. If the value is not a JSON document or cannot be parsed, the function will fail and display an error.
For NULL values, the function returns NULL.
The output format of this function follows these rules:
Each array element or object member appears on a separate line, indented one level deeper than its parent element.
Each level of indentation adds two leading spaces.
The comma separating individual array elements or object members is printed before the line break that separates two elements or members.
The key and value of an object member are separated by a colon and a space (': ').
Empty objects or arrays are printed on a single line. No space is printed between the left and right brackets.
Special characters in string scalars and key names use the same escaping rules as the JSON_QUOTE() function.
Examples
obclient> SELECT JSON_PRETTY('1234');
+--------------------+
| JSON_PRETTY('1234') |
+--------------------+
| 1234 |
+--------------------+
1 row in set
obclient> SELECT JSON_PRETTY("[1,3,5,7]");
+--------------------------+
| JSON_PRETTY("[1,3,5,7]") |
+--------------------------+
| [
1,
3,
5,
7
] |
+--------------------------+
1 row in set
obclient> SELECT JSON_PRETTY('{"a":"10","b":"20","c":"30"}');
+---------------------------------------------+
| JSON_PRETTY('{"a":"10","b":"20","c":"30"}') |
+---------------------------------------------+
| {
"a": "10",
"b": "20",
"c": "30"
} |
+---------------------------------------------+
1 row in set
