Converts JSON data into data of the STRING type. By default, automatic beautification is not performed during the conversion.
Syntax
STRING JSON_FORMAT(<json>)Parameter
json: required. This parameter specifies the JSON data you want to process.
Return value
A value of the STRING type is returned.
Examples
Example 1: Convert JSON NUMBER data into strings.
SELECT JSON_FORMAT(JSON '123');Return result:
+-----+ | _c0 | +-----+ | 123 | +-----+Example 2: Convert JSON STRING data into strings.
SELECT JSON_FORMAT(JSON '"123"');Return result:
+-----+ | _c0 | +-----+ | "123" | +-----+Example 3: Convert JSON object data into strings.
SELECT JSON_FORMAT(JSON '{"name":"Alice", "age":3, "school":"Ali"}');Return result:
+------------+ | _c0 | +------------+ | {"age":3,"name":"Alice","school":"Ali"} | +------------+Example 4: Convert JSON object array data into strings.
SELECT JSON_FORMAT( JSON '[ { "id": 1, "name":"Bob", "score":98 }, { "id":2, "name":"Alex", "score":88 } ]');Return result:
+------------+ | _c0 | +------------+ | [{"id":1,"name":"Bob","score":98},{"id":2,"name":"Alex","score":88}] | +------------+
Related functions
The JSON_FORMAT is a complex type function. For more information about functions that process complex data types, such as ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.