Skip to main content
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

Parameters

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:

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

The following example converts a simple struct to JSON:

Rows: 1Execution time: 8.89ms

The following example converts a named struct to JSON:

Rows: 1Execution time: 9.15ms

The following example converts an object literal to JSON:

Rows: 1Execution time: 5.43ms

The following example demonstrates decimal conversion to string:

Rows: 1Execution time: 6.32ms

The following example converts a complex nested structure with arrays:

Rows: 1Execution time: 15.93ms

The following example demonstrates special character escaping:

Rows: 1Execution time: 5.01ms

The following example shows NULL input handling:

Rows: 1Execution time: 6.48ms