JSON_PARSE_AS()

All functions > JSON > JSON_PARSE_AS()

Returns the value of a JSON expression represented as a string in the given type.

Signatures

Returns: The parsed JSON value cast to the specified type

JSON_PARSE_AS( expr AS type ) → T

TRY JSON_PARSE_AS( expr AS type ) → T

JSON_PARSE_AS( expr, TYPE 'type' ) → T

expr.JSON_PARSE_AS( TYPE 'type' ) → T
ParameterTypeRequiredDescription
exprVARCHARYesThe JSON string to parse
as_typeTYPEYesThe target data type to cast the parsed value to

Notes

  • Parses JSON string and casts to a specific type in one operation
  • Combines JSON_PARSE and CAST functionality
  • Useful for extracting typed values from JSON strings
  • Supports casting to numeric types (BIGINT, DOUBLE, DECIMAL)
  • Supports casting to VARCHAR and other SQL types
  • JSON_PARSE_AS(x AS T) is the operator form; JSON_PARSE_AS(x, TYPE 'T') is the function form, kept in chains (x.JSON_PARSE_AS(TYPE 'T'))
  • An invalid JSON value or an impossible cast fails the query. TRY JSON_PARSE_AS(x AS T) returns NULL instead on DuckDB, Trino and Databricks; elsewhere use TRY JSON_PARSE() and TRY CAST on JSON_EXTRACT_SCALAR
  • More efficient than separate parse and cast operations
  • as_type must be a FeatureQL type the cast layer accepts

See also

Examples

Operator form

FeatureQL
RETURN
    -- Parse and cast to BIGINT
    f1 := JSON_PARSE_AS('42' AS BIGINT),
    -- Parse and cast to DOUBLE
    f2 := JSON_PARSE_AS('3.14' AS DOUBLE),
    -- Parse and cast to VARCHAR
    f3 := JSON_PARSE_AS('"hello"' AS VARCHAR),
    -- Parse and cast to ARRAY of BIGINT
    f4 := JSON_PARSE_AS('[1, 2, 3]' AS ARRAY<BIGINT>),
    -- Parse and cast to ROW
    f5 := JSON_PARSE_AS(
        '{"name": "Alice", "age": 30}' AS ROW<name VARCHAR, age BIGINT>
    ),
    -- Parse and cast to ARRAY of ROWS
    f6 := JSON_PARSE_AS(
        '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 20}]' AS ARRAY<
            ROW<name VARCHAR, age BIGINT>
        >
    )
;
Result
f1 BIGINTf2 DECIMALf3 VARCHARf4 ARRAYf5 ROWf6 VARBINARY
423.14hello[1, 2, 3]{name: Alice, age: 30}[{name: Alice, age: 30}, {name: Bob, age: 20}]

Function form, as in a chain

FeatureQL
RETURN
    -- The function form takes a TYPE literal; FORMAT (FIX) writes the operator form
    f1 := JSON_PARSE_AS('42' AS BIGINT),
    -- A chain keeps the TYPE literal
    f2 := '42'.JSON_PARSE_AS(TYPE 'BIGINT')
;
Result
f1 BIGINTf2 BIGINT
4242