> For the complete documentation index, see [llms.txt](https://leehyokyun.gitbook.io/openbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leehyokyun.gitbook.io/openbook/1-7.-json.md).

# 1-7. JSON

간결한 데이터 표현 방법 JSON에 대하여

### 1. JSON

* JSON은 데이터를 표현하는 규격 중 하나이다.
  * ```
    Java Object
       │
       ├── Jackson ──┐
       └── Gson ─────┤
                     ↓
                   JSON
            {"id":1,"name":"Kim"}

    ```
* 데이터를 표현하기 위한 텍스트 기반 데이터 포맷으로, 특정 전문 규격에 따른 변환 과정이 Jackson/Gson 라이브러리를 통해 이루어진다.

### 2. GSON

* 구글에서 만든 Java용 JSON 변환 라이브러리
  * ```
    Gson gson = new Gson(); 
    String json = gson.toJson(order);    //**TypeAdapter
    Order order = gson.fromJson(json, Order.class); 
    ```
* 특정 형태의 데이터를 수신받은 이후, TypeAdapter 기반 각 필드(속성)을 탐색한다. 각 필드값을 JSON 기반의 값으로 변환하고, JSON 규격화한다.
* 핵심은 중간에서 JSON규격의 속성으로 변환하는 TypeAdapter이며, 동적으로 구조를 분석하는 Reflection 기반으로 동작한다. 매우 단순하고 POJO 기반의 로직 처리가 가능하며 TypeAdapter를 커스터마이징할 수 있다.
* 하지만 Spring MVC에서 기본 JSON 라이브러리인 Jackson과 다르고, Spring 생태계와 거리가 있다.

  (\*Boot 자체가 Jackson 기반)

  * Spring Boot가 출시되었을 시점에서도 기본 라이브러리는 Jackson, 이러한 역사적 배경과 더불어 안정성과 다양한 형태의 JSON 처리(확장성), 중첩구조의 처리 등 기능적 우수성으로 Jackson 선택.

### 3. Jackson

* Java 생태계에서 기본적으로 사용하는 JSON 처리 라이브러리&#x20;
  * ```
                  ObjectMapper
                       │
            ┌──────────┴──────────┐
            ↓                     ↓
       Serialization        Deserialization
            │                     │
       Serializer             Parser
            │                     │
    JsonGenerator         JsonParser
            │                     │
            ↓                     ↓
          JSON                 Java Object
    ```
* ObjectMapper 기반의 JSON 직렬화, 반대로 JSON의 Object 역직렬화가 이루어진다. 이때 세부적으로 JSON Parser를 통해 token 단위로 읽으면서 객체로 변환한다.
  * ```
                     데이터 표현 규격
                          JSON
                           │
                  ┌────────┴────────┐
                  │                 │
               Gson              Jackson
                  │                 │
                  ↓                 ↓
           Java ↔ JSON         Java ↔ JSON
                                    │
                             ┌──────┼──────┐
                             ↓      ↓      ↓
                          Binding  Tree  Streaming
    ```
* ObjectMapper의 필드/속성 역직렬화 방식은 Spring MVC에서 사용하는 기본 파싱 방식과 동일하며, 트리 구조의 변환 및 Streaming API를 통한 모던 자바식 등 지원 체계가 매우 다양하다.
* 즉, 단순 직렬화/역직렬화 뿐만 아니라 HTTP Response 메시지 변환 과정에도 관여하는 주요 요소이며,

  Gson에 비해 확장성/활용성 관점에서 매우 폭넓게, 그러면서도 세밀하게 사용이 가능한 라이브러리(체계)이다.<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://leehyokyun.gitbook.io/openbook/1-7.-json.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
