MariaDB JSON_LOOSE() Function
In MariaDB, JSON_LOOSE()
is a built-in function that adds whitespace to JSON documents to make them more readable.
The MariaDB JSON_LOOSE()
function is similar to JSON_DETAILED()
, except that JSON_DETAILED()
adds spaces, newlines and indentation to JSON documents.
JSON_COMPACT()
is opposite to this function, it removes unnecessary spaces and newlines from JSON documents.
MariaDB JSON_LOOSE()
Syntax
Here is the syntax of the MariaDB JSON_LOOSE()
function:
JSON_LOOSE(json)
Parameters
json
-
Required. The JSON document to be processed.
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_LOOSE'
.
Return value
MariaDB JSON_LOOSE()
function to remove specified spaces from a given JSON document.
If you provide an invalid JSON value or NULL
value as a parameter, JSON_LOOSE()
it will be returned NULL
.
MariaDB JSON_LOOSE()
Examples
The following example shows the usages of the MariaDB JSON_LOOSE()
function.
Basic example
SET @json_doc = '{"x":1,"b":[2,3]}';
SELECT JSON_LOOSE(@json_doc);
Output:
+-----------------------+
| JSON_LOOSE(@json_doc) |
+-----------------------+
| {"x": 1, "b": [2, 3]} |
+-----------------------+
Invalid JSON
JSON_LOOSE()
will return NULL
if you provide an invalid JSON value as a parameter.
SELECT JSON_LOOSE('{123}');
Output:
+---------------------+
| JSON_LOOSE('{123}') |
+---------------------+
| NULL |
+---------------------+
NULL
parameters
If you provide a NULL
value as an argument, JSON_LOOSE()
will return NULL
.
SELECT JSON_LOOSE(NULL);
Output:
+------------------+
| JSON_LOOSE(NULL) |
+------------------+
| NULL |
+------------------+
Conclusion
In MariaDB, JSON_LOOSE()
is a built-in function that adds whitespace to JSON documents to make them more readable.