Skip to main content

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.

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.

Syntax

TO_JSON_STRING(<input>)

Parameters

ParameterDescriptionSupported input types
<input>Any STRUCT expression to convert to JSON string format.STRUCT

Return Type

TEXT
  • If the input is NULL, the function returns NULL.
  • 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 TypeJSON RepresentationExample
TEXTJSON string'hello'"hello"
BYTEAHex string with \x prefix'string'::BYTEA"\\x737472696e67"
BOOLEANJSON booleantruetrue, falsefalse
INT, REAL, FLOATJSON number4242, 3.143.14
BIGINT, NUMERICJSON string123456789"123456789"
DATEISO date string'1998-01-01'::DATE"1998-01-01"
TIMESTAMP, TIMESTAMPNTZISO datetime string'1998-01-01'::TIMESTAMP"1998-01-01 00:00:00"
GEOGRAPHYWKB hex stringGeography point → "0101000020E610000..."
NULLJSON nullnullnull

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: