Skip to content

Export JSON ​

Choose named objects when consumers identify fields by key and positional arrays when they already know the column order. Give expressions stable aliases before writing named rows.

Named objects ​

sql
SELECT CAST('18446744073709551615' AS UInt64) AS id,
       CAST('12.50' AS Decimal(18, 2)) AS amount
FORMAT json_each_row;
text
{"id":18446744073709551615,"amount":12.50}

The digits are exact in the output. A consumer that parses every JSON number as binary floating point can still lose them; choose json_compact_each_row or json_object_each_row with the supported json_quote options when numeric strings are required. json_each_row does not apply those quoting options.

Quoted numeric output ​

sql
SELECT CAST('18446744073709551615' AS UInt64) AS id
SETTINGS json_quote_large_integers = 1
FORMAT json_compact_each_row;
text
["18446744073709551615"]

Positional rows ​

sql
SELECT 7 AS id, 'Ada' AS name
FORMAT json_compact_each_row;
text
[7, "Ada"]

The consumer must know that the first position is id and the second is name. Use a names-and-types variant when that metadata belongs in the stream.

Options ​

JSON quoting and rendering settings belong to the statement SETTINGS clause. See JSON settings, format choices and JSON loading.