MariaDB JSON_DETAILED() Function
In MariaDB, JSON_DETAILED() is a built-in function that formats the output of a JSON document so that it is easier to read.
The MariaDB JSON_DETAILED() function is similar to MySQL JSON_PRETTY() function .
JSON_COMPACT() is opposite to this function, it removes unnecessary spaces and newlines from JSON documents.
MariaDB JSON_DETAILED() Syntax
Here is the syntax of the MariaDB JSON_DETAILED() function:
JSON_DETAILED(json)
JSON_DETAILED(json, tab_size)
Parameters
json-
Required. The JSON document to be processed.
tab_size-
Optional. It specifies the tab/indent size.
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'JSON_DETAILED'.
Return value
MariaDB JSON_DETAILED() function add spaces and newlines to beautify a given JSON document.
If you provide a NULL value as an argument, JSON_DETAILED() will return NULL.
MariaDB JSON_DETAILED() Examples
The following example shows the usages of the MariaDB JSON_DETAILED() function.
Basic example
SET @json_doc = '{"x":1,"b": [2, 3]}';
SELECT JSON_DETAILED(@json_doc);
Output:
+------------------------------------------------------------+
| JSON_DETAILED(@json_doc) |
+------------------------------------------------------------+
| {
"x": 1,
"b":
[
2,
3
]
} |
+------------------------------------------------------------+Indentation size
The MariaDB JSON_DETAILED() function allows you to vary the size of the indentation using the tab_size parameter:
SET @json_doc = '{"x":1,"b": [2, 3]}';
SELECT JSON_DETAILED(@json_doc, 1);
Output:
+------------------------------------+
| JSON_DETAILED(@json_doc, 1) |
+------------------------------------+
| {
"x": 1,
"b":
[
2,
3
]
} |
+------------------------------------+NULL parameters
If you provide a NULL value as an argument, JSON_DETAILED() will return NULL.
SELECT JSON_DETAILED(NULL);
Output:
+---------------------+
| JSON_DETAILED(NULL) |
+---------------------+
| NULL |
+---------------------+Conclusion
In MariaDB, JSON_DETAILED() is a built-in function that formats the output of a JSON document so that it is easier to read.