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

> JSONObjectEachRow 포맷 문서

# JSONObjectEachRow

| 입력 | 출력 | 별칭 |
| -- | -- | -- |
| ✔  | ✔  |    |

<div id="description">
  ## 설명
</div>

이 포맷에서는 모든 데이터가 하나의 JSON 객체로 표현되며, 각 행은 [`JSONEachRow`](/ko/reference/formats/JSON/JSONEachRow) 포맷과 유사하게 해당 객체의 개별 필드로 표현됩니다.

<div id="example-usage">
  ## 사용 예시
</div>

<div id="basic-example">
  ### 기본 예시
</div>

다음과 같은 JSON이 주어졌다고 가정합니다:

```json theme={null}
{
  "row_1": {"num": 42, "str": "hello", "arr":  [0,1]},
  "row_2": {"num": 43, "str": "hello", "arr":  [0,1,2]},
  "row_3": {"num": 44, "str": "hello", "arr":  [0,1,2,3]}
}
```

객체 이름을 컬럼 값으로 사용하려면 특수 설정 [`format_json_object_each_row_column_for_object_name`](/ko/reference/settings/formats#format_json_object_each_row_column_for_object_name)을 사용할 수 있습니다.
이 설정의 값에는 컬럼 이름을 지정하며, 이 컬럼 이름은 결과 객체에서 각 행의 JSON 키로 사용됩니다.

<div id="output">
  #### 출력
</div>

`test` 테이블에 2개의 컬럼이 있다고 가정하겠습니다:

```text theme={null}
┌─object_name─┬─number─┐
│ first_obj   │      1 │
│ second_obj  │      2 │
│ third_obj   │      3 │
└─────────────┴────────┘
```

`JSONObjectEachRow` 포맷으로 출력하고, `format_json_object_each_row_column_for_object_name` 설정을 사용해 보겠습니다.

```sql title="Query" theme={null}
SELECT * FROM test SETTINGS format_json_object_each_row_column_for_object_name='object_name'
```

```json title="Response" theme={null}
{
    "first_obj": {"number": 1},
    "second_obj": {"number": 2},
    "third_obj": {"number": 3}
}
```

<div id="input">
  #### 입력
</div>

이전 예시의 출력을 `data.json` 파일에 저장해 두었다고 가정하겠습니다:

```sql title="Query" theme={null}
SELECT * FROM file('data.json', JSONObjectEachRow, 'object_name String, number UInt64') SETTINGS format_json_object_each_row_column_for_object_name='object_name'
```

```response title="Response" theme={null}
┌─object_name─┬─number─┐
│ first_obj   │      1 │
│ second_obj  │      2 │
│ third_obj   │      3 │
└─────────────┴────────┘
```

스키마 추론에도 사용할 수 있습니다:

```sql title="Query" theme={null}
DESCRIBE file('data.json', JSONObjectEachRow) SETTING format_json_object_each_row_column_for_object_name='object_name'
```

```response title="Response" theme={null}
┌─name────────┬─type────────────┐
│ object_name │ String          │
│ number      │ Nullable(Int64) │
└─────────────┴─────────────────┘
```

<div id="json-inserting-data">
  ### 데이터 삽입
</div>

```sql title="Query" theme={null}
INSERT INTO UserActivity FORMAT JSONEachRow {"PageViews":5, "UserID":"4324182021466249494", "Duration":146,"Sign":-1} {"UserID":"4324182021466249494","PageViews":6,"Duration":185,"Sign":1}
```

ClickHouse에서는 다음이 허용됩니다:

* 객체 내 key-value 쌍의 순서는 자유롭습니다.
* 일부 값은 생략할 수 있습니다.

ClickHouse는 요소 사이의 공백과 객체 뒤의 쉼표를 무시합니다. 모든 객체를 한 줄에 전달할 수 있습니다. 줄바꿈으로 구분할 필요는 없습니다.

<div id="omitted-values-processing">
  #### 생략된 값 처리
</div>

ClickHouse는 생략된 값을 해당 [데이터 타입](/ko/reference/data-types)의 기본값으로 채웁니다.

`DEFAULT expr`가 지정된 경우, ClickHouse는 [input\_format\_defaults\_for\_omitted\_fields](/ko/reference/settings/formats#input_format_defaults_for_omitted_fields) 설정에 따라 서로 다른 대체 규칙을 적용합니다.

다음 테이블을 살펴보겠습니다:

```sql title="Query" theme={null}
CREATE TABLE IF NOT EXISTS example_table
(
    x UInt32,
    a DEFAULT x * 2
) ENGINE = Memory;
```

* `input_format_defaults_for_omitted_fields = 0`이면 `x`와 `a`의 기본값은 `0`입니다(`UInt32` 데이터 타입의 기본값이 `0`이기 때문입니다).
* `input_format_defaults_for_omitted_fields = 1`이면 `x`의 기본값은 `0`이지만, `a`의 기본값은 `x * 2`입니다.

<Note>
  `input_format_defaults_for_omitted_fields = 1`로 데이터를 삽입하면, `input_format_defaults_for_omitted_fields = 0`으로 삽입할 때보다 ClickHouse가 더 많은 계산 리소스를 사용합니다.
</Note>

<div id="json-selecting-data">
  ### 데이터 조회
</div>

예시로 `UserActivity` 테이블을 살펴보겠습니다:

```response theme={null}
┌──────────────UserID─┬─PageViews─┬─Duration─┬─Sign─┐
│ 4324182021466249494 │         5 │      146 │   -1 │
│ 4324182021466249494 │         6 │      185 │    1 │
└─────────────────────┴───────────┴──────────┴──────┘
```

쿼리 `SELECT * FROM UserActivity FORMAT JSONEachRow`는 다음을 반환합니다:

```response theme={null}
{"UserID":"4324182021466249494","PageViews":5,"Duration":146,"Sign":-1}
{"UserID":"4324182021466249494","PageViews":6,"Duration":185,"Sign":1}
```

[JSON](/ko/reference/formats/JSON/JSON) 포맷과 달리, 잘못된 UTF-8 시퀀스를 대체하지 않습니다. 값은 `JSON`과 동일한 방식으로 이스케이프됩니다.

<Info>
  문자열에는 임의의 바이트 집합도 출력할 수 있습니다. 테이블의 데이터를 정보 손실 없이 JSON으로 포맷할 수 있다고 확신하는 경우 [`JSONEachRow`](/ko/reference/formats/JSON/JSONEachRow) 포맷을 사용하십시오.
</Info>

<div id="jsoneachrow-nested">
  ### 중첩 구조 사용
</div>

[`Nested`](/ko/reference/data-types/nested-data-structures) 데이터 타입 컬럼이 있는 테이블에서는 동일한 구조의 JSON 데이터를 삽입할 수 있습니다. 이 기능은 [input\_format\_import\_nested\_json](/ko/reference/settings/formats#input_format_import_nested_json) 설정을 활성화하면 사용할 수 있습니다.

예를 들어, 다음과 같은 테이블이 있다고 가정해 보겠습니다:

```sql title="Query" theme={null}
CREATE TABLE json_each_row_nested (n Nested (s String, i Int32) ) ENGINE = Memory
```

`Nested` 데이터 타입 설명에서 확인할 수 있듯이, ClickHouse는 중첩 구조의 각 구성 요소를 별도의 컬럼으로 처리합니다(이 테이블에서는 `n.s`와 `n.i`). 다음과 같은 방식으로 데이터를 삽입할 수 있습니다:

```sql title="Query" theme={null}
INSERT INTO json_each_row_nested FORMAT JSONEachRow {"n.s": ["abc", "def"], "n.i": [1, 23]}
```

데이터를 계층 구조의 JSON 객체로 삽입하려면 [`input_format_import_nested_json=1`](/ko/reference/settings/formats#input_format_import_nested_json)을 설정하세요.

```json theme={null}
{
    "n": {
        "s": ["abc", "def"],
        "i": [1, 23]
    }
}
```

이 설정이 없으면 ClickHouse가 예외를 발생시킵니다.

```sql title="Query" theme={null}
SELECT name, value FROM system.settings WHERE name = 'input_format_import_nested_json'
```

```response title="Response" theme={null}
┌─name────────────────────────────┬─value─┐
│ input_format_import_nested_json │ 0     │
└─────────────────────────────────┴───────┘
```

```sql title="Query" theme={null}
INSERT INTO json_each_row_nested FORMAT JSONEachRow {"n": {"s": ["abc", "def"], "i": [1, 23]}}
```

```response title="Response" theme={null}
Code: 117. DB::Exception: Unknown field found while parsing JSONEachRow format: n: (at row 1)
```

```sql title="Query" theme={null}
SET input_format_import_nested_json=1
INSERT INTO json_each_row_nested FORMAT JSONEachRow {"n": {"s": ["abc", "def"], "i": [1, 23]}}
SELECT * FROM json_each_row_nested
```

```response title="Response" theme={null}
┌─n.s───────────┬─n.i────┐
│ ['abc','def'] │ [1,23] │
└───────────────┴────────┘
```

<div id="format-settings">
  ## 포맷 설정
</div>

| 설정                                                                                                                                                                | 설명                                                                                                                  | 기본값      | 비고                                                                                                                                                     |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`input_format_import_nested_json`](/ko/reference/settings/formats#input_format_import_nested_json)                                                               | 중첩된 JSON 데이터를 중첩 테이블에 매핑합니다. 이 설정은 JSONEachRow 포맷에서 작동합니다.                                                          | `false`  |                                                                                                                                                        |
| [`input_format_json_read_bools_as_numbers`](/ko/reference/settings/formats#input_format_json_read_bools_as_numbers)                                               | JSON 입력 형식에서 bool 값을 숫자로 파싱할 수 있도록 허용합니다.                                                                           | `true`   |                                                                                                                                                        |
| [`input_format_json_read_bools_as_strings`](/ko/reference/settings/formats#input_format_json_read_bools_as_strings)                                               | JSON 입력 형식에서 bool 값을 문자열로 파싱할 수 있도록 합니다.                                                                            | `true`   |                                                                                                                                                        |
| [`input_format_json_read_numbers_as_strings`](/ko/reference/settings/formats#input_format_json_read_numbers_as_strings)                                           | JSON 입력 형식에서 숫자 값을 문자열로 파싱할 수 있도록 합니다.                                                                              | `true`   |                                                                                                                                                        |
| [`input_format_json_read_arrays_as_strings`](/ko/reference/settings/formats#input_format_json_read_arrays_as_strings)                                             | JSON 입력 형식에서 JSON 배열을 문자열로 파싱할 수 있도록 합니다.                                                                           | `true`   |                                                                                                                                                        |
| [`input_format_json_read_objects_as_strings`](/ko/reference/settings/formats#input_format_json_read_objects_as_strings)                                           | JSON 입력 형식에서 JSON 객체를 문자열로 파싱할 수 있도록 합니다.                                                                           | `true`   |                                                                                                                                                        |
| [`input_format_json_named_tuples_as_objects`](/ko/reference/settings/formats#input_format_json_named_tuples_as_objects)                                           | named tuple 컬럼을 JSON 객체로 파싱합니다.                                                                                     | `true`   |                                                                                                                                                        |
| [`input_format_json_try_infer_numbers_from_strings`](/ko/reference/settings/formats#input_format_json_try_infer_numbers_from_strings)                             | 스키마 추론 중 문자열 필드에서 숫자를 추론합니다.                                                                                        | `false`  |                                                                                                                                                        |
| [`input_format_json_try_infer_named_tuples_from_objects`](/ko/reference/settings/formats#input_format_json_try_infer_named_tuples_from_objects)                   | 스키마 추론 중 JSON 객체에서 named tuple을 추론합니다.                                                                              | `true`   |                                                                                                                                                        |
| [`input_format_json_infer_incomplete_types_as_strings`](/ko/reference/settings/formats#input_format_json_infer_incomplete_types_as_strings)                       | JSON 입력 형식에서 스키마 추론 중 Null 또는 빈 객체/배열만 포함하는 키에는 String 유형을 사용합니다.                                                   | `true`   |                                                                                                                                                        |
| [`input_format_json_defaults_for_missing_elements_in_named_tuple`](/ko/reference/settings/formats#input_format_json_defaults_for_missing_elements_in_named_tuple) | named tuple을 파싱할 때 JSON 객체에서 누락된 요소에 기본값을 삽입합니다.                                                                    | `true`   |                                                                                                                                                        |
| [`input_format_json_ignore_unknown_keys_in_named_tuple`](/ko/reference/settings/formats#input_format_json_ignore_unknown_keys_in_named_tuple)                     | named tuple의 JSON 객체에서 알 수 없는 키를 무시합니다.                                                                             | `false`  |                                                                                                                                                        |
| [`input_format_json_compact_allow_variable_number_of_columns`](/ko/reference/settings/formats#input_format_json_compact_allow_variable_number_of_columns)         | JSONCompact/JSONCompactEachRow 포맷에서 가변적인 수의 컬럼을 허용하고, 추가 컬럼은 무시하며, 누락된 컬럼에는 기본값을 사용합니다.                             | `false`  |                                                                                                                                                        |
| [`input_format_json_throw_on_bad_escape_sequence`](/ko/reference/settings/formats#input_format_json_throw_on_bad_escape_sequence)                                 | JSON 문자열에 잘못된 이스케이프 시퀀스가 포함되어 있으면 예외를 발생시킵니다. 비활성화하면 잘못된 이스케이프 시퀀스는 데이터에 그대로 유지됩니다.                                 | `true`   |                                                                                                                                                        |
| [`input_format_json_empty_as_default`](/ko/reference/settings/formats#input_format_json_empty_as_default)                                                         | JSON 입력의 빈 필드를 기본값으로 간주합니다.                                                                                         | `false`. | 복잡한 기본값 표현식을 사용하는 경우 [`input_format_defaults_for_omitted_fields`](/ko/reference/settings/formats#input_format_defaults_for_omitted_fields)도 활성화해야 합니다. |
| [`output_format_json_quote_64bit_integers`](/ko/reference/settings/formats#output_format_json_quote_64bit_integers)                                               | JSON 출력 형식에서 64비트 정수를 따옴표로 묶어 출력할지 제어합니다.                                                                           | `true`   |                                                                                                                                                        |
| [`output_format_json_quote_64bit_floats`](/ko/reference/settings/formats#output_format_json_quote_64bit_floats)                                                   | JSON 출력 형식에서 64비트 부동소수점 수를 따옴표로 묶어 출력할지 제어합니다.                                                                      | `false`  |                                                                                                                                                        |
| [`output_format_json_quote_denormals`](/ko/reference/settings/formats#output_format_json_quote_denormals)                                                         | JSON 출력 형식에서 '+nan', '-nan', '+inf', '-inf'를 출력할 수 있도록 합니다.                                                         | `false`  |                                                                                                                                                        |
| [`output_format_json_quote_decimals`](/ko/reference/settings/formats#output_format_json_quote_decimals)                                                           | JSON 출력 형식에서 소수 값을 따옴표로 묶을지 여부를 제어합니다.                                                                              | `false`  |                                                                                                                                                        |
| [`output_format_json_escape_forward_slashes`](/ko/reference/settings/formats#output_format_json_escape_forward_slashes)                                           | JSON 출력 형식에서 문자열을 출력할 때 슬래시(/)를 이스케이프 처리할지 제어합니다.                                                                   | `true`   |                                                                                                                                                        |
| [`output_format_json_named_tuples_as_objects`](/ko/reference/settings/formats#output_format_json_named_tuples_as_objects)                                         | named tuple 컬럼을 JSON 객체로 직렬화합니다.                                                                                    | `true`   |                                                                                                                                                        |
| [`output_format_json_array_of_rows`](/ko/reference/settings/formats#output_format_json_array_of_rows)                                                             | JSONEachRow(Compact) 포맷에서 모든 행을 JSON 배열로 출력합니다.                                                                     | `false`  |                                                                                                                                                        |
| [`output_format_json_validate_utf8`](/ko/reference/settings/formats#output_format_json_validate_utf8)                                                             | JSON 출력 형식에서 UTF-8 시퀀스 검증을 활성화합니다(JSON/JSONCompact/JSONColumnsWithMetadata 포맷에는 영향을 주지 않으며, 이들 포맷은 항상 utf8을 검증합니다). | `false`  |                                                                                                                                                        |
