Skip to main content

Categories: Variant Type

PARSE_JSON Preview

Parses a JSON string into a VARIANT value.

Syntax

PARSE_JSON(json_string VARCHAR) → VARIANT

  • json_string: A string containing valid JSON.

Examples

PARSE_JSON example
SELECT PARSE_JSON('{"name": "Alice", "age": 30}')
-- (VARIANT) {"name":"Alice","age":30}
PARSE_JSON example
SELECT PARSE_JSON('[1, 2, 3]')
-- (VARIANT) [1,2,3]
PARSE_JSON example
SELECT PARSE_JSON('{"user": {"id": 1, "tags": ["admin", "active"]}}')
-- (VARIANT) {"user":{"id":1,"tags":["admin","active"]}}

Usage Notes

JSON type handling

When parsing JSON, values are mapped to VARIANT internal types as follows:

  • Integer numbers become BIGINT
  • Fractional numbers become DOUBLE
  • Strings become VARCHAR
  • Booleans become BOOLEAN
  • null becomes VARIANT null
  • Arrays become VARIANT<ARRAY>
  • Structs become VARIANT<STRUCT>

Because JSON has no representation for dates, times, timestamps, UUIDs, or binary data, these values remain as strings after parsing. Extracting them later with VARIANT_GET requires a type conversion on each read. To preserve original SQL types in a VARIANT, use TO_VARIANT instead.

Invalid JSON

If the input string is not valid JSON, PARSE_JSON raises an error. Use TRY_PARSE_JSON to return NULL instead of raising an error.

Extracting values

After parsing JSON into a VARIANT, use VARIANT_GET to extract specific values by path.