> ## 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.

> JSONAsString 格式文档

# JSONAsString

| 输入 | 输出 | 别名 |
| -- | -- | -- |
| ✔  | ✗  |    |

<div id="description">
  ## 说明
</div>

在这种格式中，单个 JSON 对象会被解释为单个值。
如果输入包含多个 JSON 对象 (以逗号分隔) ，它们会被解释为不同的行。
如果输入数据用 `[]` 括起来，则会被解释为 JSON 对象数组。

<Note>
  这种格式只能解析为仅包含一个 [String](/zh/reference/data-types/string) 类型字段的表。
  其余列必须设置为 [`DEFAULT`](/zh/reference/statements/create/table#default) 或 [`MATERIALIZED`](/zh/reference/statements/create/view#materialized-view)，
  或者省略。
</Note>

将整个 JSON 对象序列化为 String 后，您可以使用 [JSON 函数](/zh/reference/functions/regular-functions/json-functions) 对其进行处理。

<div id="example-usage">
  ## 示例用法
</div>

<div id="basic-example">
  ### 基本示例
</div>

```sql title="Query" theme={null}
DROP TABLE IF EXISTS json_as_string;
CREATE TABLE json_as_string (json String) ENGINE = Memory;
INSERT INTO json_as_string (json) FORMAT JSONAsString {"foo":{"bar":{"x":"y"},"baz":1}},{},{"any json stucture":1}
SELECT * FROM json_as_string;
```

```response title="Response" theme={null}
┌─json──────────────────────────────┐
│ {"foo":{"bar":{"x":"y"},"baz":1}} │
│ {}                                │
│ {"any json stucture":1}           │
└───────────────────────────────────┘
```

<div id="an-array-of-json-objects">
  ### JSON 对象数组
</div>

```sql title="Query" theme={null}
CREATE TABLE json_square_brackets (field String) ENGINE = Memory;
INSERT INTO json_square_brackets FORMAT JSONAsString [{"id": 1, "name": "name1"}, {"id": 2, "name": "name2"}];

SELECT * FROM json_square_brackets;
```

```response title="Response" theme={null}
┌─field──────────────────────┐
│ {"id": 1, "name": "name1"} │
│ {"id": 2, "name": "name2"} │
└────────────────────────────┘
```

<div id="format-settings">
  ## 格式设置
</div>
