> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentación sobre el formato JSONAsObject

# JSONAsObject

<div id="description">
  ## Descripción
</div>

En este formato, un único objeto JSON se interpreta como un único valor [JSON](/es/reference/data-types/newjson). Si la entrada contiene varios objetos JSON (separados por comas), se interpretan como filas distintas. Si los datos de entrada están entre `[]`, se interpretan como un array de JSON.

Este formato solo puede analizarse en una tabla con un único campo de tipo [JSON](/es/reference/data-types/newjson). Las columnas restantes deben establecerse como [`DEFAULT`](/es/reference/statements/create/table#default) o [`MATERIALIZED`](/es/reference/statements/create/view#materialized-view).

<div id="example-usage">
  ## Ejemplo de uso
</div>

<div id="basic-example">
  ### Ejemplo básico
</div>

```sql title="Query" theme={null}
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" theme={null}
{"json":{"foo":{"bar":{"x":"y"},"baz":"1"}}}
{"json":{}}
{"json":{"any json stucture":"1"}}
```

<div id="an-array-of-json-objects">
  ### Un array de objetos JSON
</div>

```sql title="Query" theme={null}
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" theme={null}
{"field":{"id":"1","name":"name1"}}
{"field":{"id":"2","name":"name2"}}
```

<div id="columns-with-default-values">
  ### Columnas con valores por defecto
</div>

```sql title="Query" theme={null}
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" theme={null}
{"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"}}}
```

<div id="format-settings">
  ## Ajustes de formato
</div>
