ClickHouse/docs/zh/faq/integration/json-import.md

35 lines
1.5 KiB
Markdown
Raw Normal View History

2022-04-10 23:08:18 +00:00
---
2022-08-26 19:07:59 +00:00
slug: /zh/faq/integration/json-import
2022-04-10 23:08:18 +00:00
title: How to import JSON into ClickHouse?
toc_hidden: true
sidebar_position: 11
---
# How to Import JSON Into ClickHouse? {#how-to-import-json-into-clickhouse}
2023-03-17 18:21:11 +00:00
ClickHouse supports a wide range of [data formats for input and output](../../interfaces/formats/). There are multiple JSON variations among them, but the most commonly used for data ingestion is [JSONEachRow](../../interfaces/formats/#jsoneachrow). It expects one JSON object per row, each object separated by a newline.
2022-04-10 23:08:18 +00:00
## Examples {#examples}
2023-03-17 18:21:11 +00:00
Using [HTTP interface](../../interfaces/http/):
2022-04-10 23:08:18 +00:00
``` bash
$ echo '{"foo":"bar"}' | curl 'http://localhost:8123/?query=INSERT%20INTO%20test%20FORMAT%20JSONEachRow' --data-binary @-
```
2023-03-17 18:21:11 +00:00
Using [CLI interface](../../interfaces/cli/):
2022-04-10 23:08:18 +00:00
``` bash
$ echo '{"foo":"bar"}' | clickhouse-client --query="INSERT INTO test FORMAT JSONEachRow"
```
2023-03-17 18:21:11 +00:00
Instead of inserting data manually, you might consider to use one of [client libraries](../../interfaces/) instead.
2022-04-10 23:08:18 +00:00
## Useful Settings {#useful-settings}
- `input_format_skip_unknown_fields` allows to insert JSON even if there were additional fields not present in table schema (by discarding them).
2023-03-17 18:21:11 +00:00
- `input_format_import_nested_json` allows to insert nested JSON objects into columns of [Nested](../../sql-reference/data-types/nested-data-structures/nested/) type.
2022-04-10 23:08:18 +00:00
2023-03-17 18:21:11 +00:00
:::note
2022-04-10 23:08:18 +00:00
Settings are specified as `GET` parameters for the HTTP interface or as additional command-line arguments prefixed with `--` for the `CLI` interface.
:::