Converts SQL STRUCT value to a valid JSON string representation. Struct field names become JSON object keys, and nested structures are converted to nested JSON objects and arrays.Documentation Index
Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<input> | Any STRUCT expression to convert to JSON string format. | STRUCT |
Return Type
TEXT
- If the input is
NULL, the function returnsNULL. - The function always produces a valid JSON string for non-null inputs.
Type Conversions
The following table shows how Firebolt data types are converted to JSON:| Firebolt Type | JSON Representation | Example |
|---|---|---|
TEXT | JSON string | 'hello' → "hello" |
BYTEA | Hex string with \x prefix | 'string'::BYTEA → "\\x737472696e67" |
BOOLEAN | JSON boolean | true → true, false → false |
INT, REAL, FLOAT | JSON number | 42 → 42, 3.14 → 3.14 |
BIGINT, NUMERIC | JSON string | 123456789 → "123456789" |
DATE | ISO date string | '1998-01-01'::DATE → "1998-01-01" |
TIMESTAMP, TIMESTAMPNTZ | ISO datetime string | '1998-01-01'::TIMESTAMP → "1998-01-01 00:00:00" |
GEOGRAPHY | WKB hex string | Geography point → "0101000020E610000..." |
NULL | JSON null | null → null |
Behavior
- Struct conversion: Struct field names become JSON object keys. If a struct has unnamed fields, they are automatically named
f1,f2,f3, etc. - Nested structures: Nested structs become nested JSON objects, and arrays become JSON arrays.
- NULL handling: NULL input returns NULL. NULL fields within structs become JSON null values.
- Escaping: The function uses official json escaping that includes forward slashes (
/becomes\/).
Examples
Example The following example converts a simple struct to JSON:Example The following example converts a named struct to JSON:
Example The following example converts an object literal to JSON:
Example The following example demonstrates decimal conversion to string:
Example The following example converts a complex nested structure with arrays:
Example The following example demonstrates special character escaping:
Example The following example shows NULL input handling: