Parses a string as JSON and returns a value of the JSON type. Use this function to convert a string column into the JSON type so you can then extract fields with JSON path expressions or other JSON functions.
If the input string is not valid JSON, the function throws an error.
Syntax
json json_parse(<string>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
string | Yes | STRING | The string to parse. |
Return value
Returns a value of the JSON type.
Examples
The following examples show how json_parse handles different types of valid JSON input and an invalid input.
-- JSON object
SELECT json_parse('{"a":1, "b":2}'); -- {"a":1,"b":2}
-- JSON string
SELECT json_parse('"abc"'); -- "abc"
-- Invalid input — throws an error
SELECT json_parse('abc');
-- Invalid input syntax for type json, detail:Token "abc" is invalid.Related functions
json_parse is a complex type function. For the full list of functions that handle ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.