Skip to main content

Description

In this format, all data is represented as a single JSON Object, with each row represented as a separate field of this object similar to the JSONEachRow format.

Example usage

Basic example

Given some JSON:
To use an object name as a column value you can use the special setting format_json_object_each_row_column_for_object_name. The value of this setting is set to the name of a column, that is used as JSON key for a row in the resulting object.

Output

Let’s say we have the table test with two columns:
Let’s output it in the JSONObjectEachRow format and use the format_json_object_each_row_column_for_object_name setting:
Query
Response

Input

Let’s say we stored the output from the previous example in a file named data.json:
Query
Response
It also works for schema inference:
Query
Response

Inserting data

Query
ClickHouse allows:
  • Any order of key-value pairs in the object.
  • Omitting some values.
ClickHouse ignores spaces between elements and commas after the objects. You can pass all the objects in one line. You do not have to separate them with line breaks.

Omitted values processing

ClickHouse substitutes omitted values with the default values for the corresponding data types. If DEFAULT expr is specified, ClickHouse uses different substitution rules depending on the input_format_defaults_for_omitted_fields setting. Consider the following table:
Query
  • If input_format_defaults_for_omitted_fields = 0, then the default value for x and a equals 0 (as the default value for the UInt32 data type).
  • If input_format_defaults_for_omitted_fields = 1, then the default value for x equals 0, but the default value of a equals x * 2.
When inserting data with input_format_defaults_for_omitted_fields = 1, ClickHouse consumes more computational resources, compared to insertion with input_format_defaults_for_omitted_fields = 0.

Selecting data

Consider the UserActivity table as an example:
The query SELECT * FROM UserActivity FORMAT JSONEachRow returns:
Unlike the JSON format, there is no substitution of invalid UTF-8 sequences. Values are escaped in the same way as for JSON.
Any set of bytes can be output in the strings. Use the JSONEachRow format if you are sure that the data in the table can be formatted as JSON without losing any information.

Usage of Nested Structures

If you have a table with the Nested data type columns, you can insert JSON data with the same structure. Enable this feature with the input_format_import_nested_json setting. For example, consider the following table:
Query
As you can see in the Nested data type description, ClickHouse treats each component of the nested structure as a separate column (n.s and n.i for our table). You can insert data in the following way:
Query
To insert data as a hierarchical JSON object, set input_format_import_nested_json=1.
Without this setting, ClickHouse throws an exception.
Query
Response
Query
Response
Query
Response

Format settings

Last modified on July 2, 2026