PARSE_JSON

functionsupportedCore SQL functions

docs.snowflake.com ↗

Semi-structured and structured data functions

Interprets an input string as a JSON document, producing a VARIANT value. You can use the PARSE_JSON function when you have input data in JSON format. This function can convert data from JSON format to ARRAY or OBJECT data and store that data directly in a VARIANT value. You can then analyze or manipulate the data. By default, the function doesn’t allow duplicate keys in the JSON object, but you can set the 'parameter' argument to allow duplicate keys.

Syntax

supportedpartialnot supportednot scored

PARSE_JSON( <expr> [ , '<parameter>' ] )

Parameters

NameRequiredDescription
exprrequiredAn expression of string type (for example, VARCHAR) that holds valid JSON information.
'parameter'optionalString constant that specifies the parameter used to search for matches. Supported values: Parameter Description d Allow duplicate keys in JSON objects. If a JSON object contains a duplicate key, the returned object has a single instance of that key with the last value specified for that key. s Don’t allow duplicate keys in JSON objects (strict). This value is the default.ExpandShow lessSee more

Returns

Returns a value of type VARIANT that contains a JSON document. If the input is NULL, the function returns NULL. This function doesn’t return a structured type.

Usage notes

Handling NULL values with the PARSE_JSON and TO_JSON functions

The following example shows how PARSE_JSON and TO_JSON handle NULL values:

Comparing PARSE_JSON and TO_JSON

The following examples demonstrate the relationship between the PARSE_JSON and TO_JSON functions. This example creates a table with a VARCHAR column and a VARIANT column. The INSERT statement inserts a VARCHAR value, and the UPDATE statement generates a JSON value that corresponds with that VARCHAR value. This query shows that TO_JSON and PARSE_JSON are conceptually reciprocal functions: However, the functions are not exactly reciprocal. Differences in whitespace or in the order of key-value pairs can prevent the output from matching the input. For example: Although both the PARSE_JSON function and the TO_VARIANT function can take a string and return a VARIANT value, they are not equivalent. The following example creates a table with two VARIANT columns. Then, it uses PARSE_JSON to insert a value into one column and TO_VARIANT to insert a value into the other column. The query below shows that the functions returned VARIANT values that store values of different data types.

See also