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: VARCHAR, as_type: TYPE) → T sql
| 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
- Returns NULL if parsing fails or cast is not possible
- More efficient than separate parse and cast operations
- Type must be a valid SQL data type
Examples
FeatureQL
SELECT
f1 := JSON_PARSE_AS('42', TYPE 'BIGINT'), -- Parse and cast to BIGINT
f2 := JSON_PARSE_AS('3.14', TYPE 'DOUBLE'), -- Parse and cast to DOUBLE
f3 := JSON_PARSE_AS('"hello"', TYPE 'VARCHAR'), -- Parse and cast to VARCHAR
f4 := JSON_PARSE_AS('[1, 2, 3]', TYPE 'ARRAY(BIGINT)'), -- Parse and cast to ARRAY of BIGINT
f5 := JSON_PARSE_AS('{"name": "Alice", "age": 30}', TYPE 'ROW(name VARCHAR, age BIGINT)'), -- Parse and cast to ROW
f6 := JSON_PARSE_AS('[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 20}]', TYPE 'ARRAY(ROW(name VARCHAR, age BIGINT))') -- Parse and cast to ARRAY of ROWS
;Result
| f1 BIGINT | f2 VARCHAR | f3 VARCHAR | f4 ARRAY | f5 ROW | f6 VARCHAR |
|---|---|---|---|---|---|
| 42 | 3.14 | hello | [1, 2, 3] | {name: Alice, age: 30} | [{name: Alice, age: 30}, {name: Bob, age: 20}] |
On this page