JSON_PARSE

Updated at:

Converts a STRING value to a JSON value. An error occurs if the string is not in a valid JSON format.

Command format

json json_parse(<string>)

Parameters

string: Required. The STRING value to process.

Return value

Returns a value of the JSON type.

Examples

  • Example 1: Convert a string to the JSON type.

    select json_parse('{"a":1, "b":2}');

    The return value is:

    +-----+
    | _c0 |
    +-----+
    | {"a":1,"b":2} |
    +-----+
  • Example 2: Convert a string to the JSON type.

    select json_parse('"abc"');

    The return value is:

    +-----+
    | _c0 |
    +-----+
    | "abc" |
    +-----+
  • Example 3: An error occurs when converting an invalid string.

    select json_parse('abc');

    The return value is:

    Invalid input syntax for type json, detail:Token "abc" is invalid.

Related functions

JSON_PARSE is a complex type function. For more information about functions that process complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.