Files
Alexey MilovidovandClaude Opus 4.8 da800c515f Docs: autogenerate 65 format reference pages from system.formats
Extend the generator to formats (generate-formats.sql + format_generators in
the port, same mechanism as engines). Convert the 65 format pages whose
structured docs reproduce the page (content-neutral / whitespace-only).

Deferred (kept hand-written): pages that include shared Mintlify snippets
(<PrettyFormatSettings/>, <RowBinaryFormatSettings/>, <DataTypeMapping/> from
/snippets/) which the Docusaurus->Mintlify transform can't synthesize, and a
few (Values, HiveText, Arrow, ArrowStream, Parquet) whose structured
description is less complete than the page and needs enriching.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 20:52:34 +00:00

66 lines
2.4 KiB
Plaintext

---
alias: []
description: 'Documentation for the JSONAsObject format'
input_format: true
keywords: ['JSONAsObject']
output_format: false
slug: /interfaces/formats/JSONAsObject
title: 'JSONAsObject'
doc_type: 'reference'
---
{/*AUTOGENERATED_START*/}
## Description {#description}
In this format, a single JSON object is interpreted as a single [JSON](/reference/data-types/newjson) value. If the input has several JSON objects (comma separated), they are interpreted as separate rows. If the input data is enclosed in `[]`, it is interpreted as an array of JSONs.
This format can only be parsed for a table with a single field of type [JSON](/reference/data-types/newjson). The remaining columns must be set to [`DEFAULT`](/reference/statements/create/table#default) or [`MATERIALIZED`](/reference/statements/create/view#materialized-view).
## Example usage {#example-usage}
### Basic example {#basic-example}
```sql title="Query"
CREATE TABLE json_as_object (json JSON) ENGINE = Memory;
INSERT INTO json_as_object (json) FORMAT JSONAsObject {"foo":{"bar":{"x":"y"},"baz":1}},{},{"any json stucture":1}
SELECT * FROM json_as_object FORMAT JSONEachRow;
```
```response title="Response"
{"json":{"foo":{"bar":{"x":"y"},"baz":"1"}}}
{"json":{}}
{"json":{"any json stucture":"1"}}
```
### An array of JSON objects {#an-array-of-json-objects}
```sql title="Query"
CREATE TABLE json_square_brackets (field JSON) ENGINE = Memory;
INSERT INTO json_square_brackets FORMAT JSONAsObject [{"id": 1, "name": "name1"}, {"id": 2, "name": "name2"}];
SELECT * FROM json_square_brackets FORMAT JSONEachRow;
```
```response title="Response"
{"field":{"id":"1","name":"name1"}}
{"field":{"id":"2","name":"name2"}}
```
### Columns with default values {#columns-with-default-values}
```sql title="Query"
CREATE TABLE json_as_object (json JSON, time DateTime MATERIALIZED now()) ENGINE = Memory;
INSERT INTO json_as_object (json) FORMAT JSONAsObject {"foo":{"bar":{"x":"y"},"baz":1}};
INSERT INTO json_as_object (json) FORMAT JSONAsObject {};
INSERT INTO json_as_object (json) FORMAT JSONAsObject {"any json stucture":1}
SELECT time, json FROM json_as_object FORMAT JSONEachRow
```
```response title="Response"
{"time":"2024-09-16 12:18:10","json":{}}
{"time":"2024-09-16 12:18:13","json":{"any json stucture":"1"}}
{"time":"2024-09-16 12:18:08","json":{"foo":{"bar":{"x":"y"},"baz":"1"}}}
```
## Format settings {#format-settings}
{/*AUTOGENERATED_END*/}