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
| Parameter | Type | Required | Description |
|---|---|---|---|
expr | VARCHAR | Yes | The JSON string to parse |
as_type | TYPE | Yes | The 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_typemust 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 BIGINT | f2 DECIMAL | f3 VARCHAR | f4 ARRAY | f5 ROW | f6 VARBINARY |
|---|---|---|---|---|---|
| 42 | 3.14 | hello | [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 BIGINT | f2 BIGINT |
|---|---|
| 42 | 42 |