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
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
  • 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 BIGINTf2 VARCHARf3 VARCHARf4 ARRAYf5 ROWf6 VARCHAR
423.14hello[1, 2, 3]{name: Alice, age: 30}[{name: Alice, age: 30}, {name: Bob, age: 20}]

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19