JSON values, without parsing any JSON strings in the input. Arrays and structs are converted recursively into JSON arrays and JSON objects, respectively. Scalar values other than BOOLEAN, INTEGER, BIGINT, REAL, DOUBLE, or TEXT are converted to TEXT using the regular CAST function.
Syntax
Parameters
| Parameter | Description | Supported Input Types |
|---|---|---|
<value> | The value that should be converted to JSON. | Any |
Return Type
JSON
- If
<value>isNULLthe return value is SQLNULL. - If
<value>is an array or struct containing nested SQLNULLvalues, these nested SQLNULLs are converted to JSONnulls.
Examples
Example The following query converts aSTRUCT value containing nested STRUCT, ARRAY, and scalar values to JSON. All of the scalar data types involved are natively representable in JSON.
| ?column? (JSON) |
|---|
{"a":[{"b":{"42":"the answer","message":"hello world!"}}]} |
STRUCT value containing nested STRUCT, ARRAY, and NULL values to JSON.
| ?column? (JSON) |
|---|
{"a":[{"b":{"message":null}}]} |
NULL value to JSON. Since the value is not nested within an ARRAY or STRUCT, it remains a SQL NULL value.
NULL value:
| ?column? (JSON) |
|---|
| NULL |
TIMESTAMP value to JSON. Since TIMESTAMP values are not natively representable in JSON, they are converted to TEXT and represented as JSON strings.
| ?column? (JSON) |
|---|
"2026-01-01 00:00:00" |
TEXT value containing valid JSON data to JSON. Note that the return value simply consists of a single JSON string though, i.e. the TO_JSON function does not parse JSON data contained in strings.
| ?column? (JSON) |
|---|
"{\"a\":\"b\"}" |