Purpose
JSON_PRETTY() prints out JSON values in the specified format. It is similar to PHP functions.
Syntax
JSON_PRETTY(json_val)
Description
The value of json_val must be a JSON value or a valid string representation of a JSON value. Extra spaces and line breaks in the value do not affect the output. If the value is not a JSON document or cannot be parsed, this function fails and returns an error.
If the value is NULL, this function returns NULL.
The output of this function conforms to the following rules:
Each array element or object member appears in a separate line, with one level of indentation compared with its parent element.
Two leading spaces are added for each level of indentation.
The comma (,) that separates a single array element or object member is placed before the line break that separates two elements or members.
The key and value of an object member are separated with a colon (:) followed by a space.
A null object or array is displayed in one line. No space is added between the left parenthesis and the right parenthesis.
Special characters in scalar values of strings and key names conform to the same escape rules for 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