> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TO_JSON

> Serializes a SQL struct, array or map value to JSON text.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

A NULL top-level input returns SQL NULL; nested NULL values are emitted as JSON null.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
to_json(value)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRUCT, ARRAY or MAP | Yes | Value to serialize. Nested scalar values can be BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, DATE or TIMESTAMP. ARRAY elements, MAP values and STRUCT fields can contain further ARRAY, MAP and STRUCT values with these scalar leaves. BINARY and TIME leaves are unsupported. |

## Returns

* Type: STRING
* NULL behavior: A NULL top-level input returns SQL NULL; nested NULL values are emitted as JSON null.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Partial (JSON serialization changes representation; floating special values become JSON null.) |

## Usage notes

* Takes exactly one STRUCT, ARRAY, or MAP argument. Other scalar inputs and additional format arguments are not supported.
* Default date format is yyyy-MM-dd; default timestamp format is yyyy-MM-dd'T'HH:mm:ss\[.SSS]\[XXX].
* Nonfinite floating values are emitted as JSON null.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT to_json(named_struct('a', 7)) AS "value";
```

| value |
| - |
| \{"a":7} |

### Serialize an array with a NULL element

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT to_json(ARRAY(1, CAST(NULL AS INT), 3)) AS json_text;
```

| json\_text |
| - |
| \[1,null,3] |

## Limitations

* Custom date or timestamp format arguments are not supported.
* BINARY and TIME fields or elements raise an error. The supported STRUCT form does not establish support for serializing a logical VARIANT value.

## Related functions

* [from\_json](/query/sql/functions/json/from_json)
* [json\_format](/query/sql/functions/json/json_format)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.