# SpreadJS에서의 JSON 스키마

## Content

공용 스키마는 SpreadJS JSON 데이터 형식을 설명하며, SpreadJS JSON 데이터를 사람이 읽기 쉽고 기계가 읽을 수 있는 문서로 명확하게 만들어 줍니다. 또한 JSON 데이터를 코드로 생성하거나 자동화된 테스트 및 검증을 수행할 때 유용한 완전한 구조적 유효성 검사를 제공합니다. 최신 및 전체 스키마 목록은 [SpreadJS 스프레드 스키마](/spreadjs/docs/v18/features/jsonschema/fullschema)를 참고하세요.
JSON Schema에 대한 자세한 내용은 [json-schema.org](http://json-schema.org) 웹사이트를 참고하세요.
JSON Schema 문서를 사용하여 JSON 데이터가 유효한지 확인할 수 있습니다. 또한 JSON Schema에 따라 유효한 JSON 데이터를 생성할 수도 있습니다.
다음은 JSON Schema의 기본 예시입니다:

```json
{
    "title": "LineBorder",
        "description": "테두리 선의 색상을 나타냅니다. 알려진 색상 이름 또는 HEX 스타일 색상 값을 사용할 수 있습니다. 기본값은 black입니다.",
            "type": "object",
                "properties": {
        "color": {
            "type": "string",
                "default": "black"
        },
        "style": {
            "$ref": "#/definitions/LineStyle",
                "default": 0
        }
    }
}
```

테마를 사용하여 유효성 검사기를 만드는 방법에 대한 정보는 [http://json-schema.org/implementations.html](http://json-schema.org/implementations) 웹사이트를 참고하세요. SpreadJS JSON Schema 문서를 사용하여 SpreadJS JSON 데이터를 검증할 수 있습니다.
다음 단계는 json-schema-validator를 사용하여 SpreadJS JSON 데이터를 검증하는 방법을 보여줍니다.

1. JSON 데이터 일부 검증하기
    * 예를 들어, "NameInfo"라는 2개의 JSON 데이터가 있고, 이들이 모두 유효한 JSON 데이터인지 확인하려고 한다고 가정합니다.

        ```json
        {
            "name":"name1",
            "row":4,
            "column":3,
            "formula":"=SUM(A1,A3)"
        }
        ```

        ```json
        {
            "name":"name1",
            "row":"4",
            "column":3,
            "formula":"=SUM(A1,A3)"
        }
        ```

        다음과 같이 "NameInfo"의 JSON Schema 문서를 가져올 수 있습니다:

        ```json
        {
              "title": "NameInfo",
              "description": "수식에서 사용할 수 있는 사용자 정의 이름이 지정된 수식을 나타냅니다.",
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "row": {
                  "type": "integer",
                  "minimum": 0
                },
                "col": {
                  "type": "integer",
                  "minimum": 0
                },
                "formula": {
                  "type": "string"
                },
                "comment": {
                  "type": "string"
                }
              }
            }
        ```

        JSON Schema를 사용하여 JSON 데이터를 검증할 수 있습니다. 위 예시에서 "jsonData2"는 유효하지 않습니다. 해당 속성 "row"의 타입은 "integer"여야 합니다.
    * JSON 스키마가 다른 JSON 스키마를 참조하는 경우도 있습니다. 예를 들어, 다음 JSON Schema는 "LineStyle"이라는 다른 JSON Schema를 참조합니다.

        ```json
        {
            "title" : "LineBorder",
            "description" : "테두리 선의 색상을 나타냅니다. 알려진 색상 이름 또는 HEX 스타일 색상 값을 사용할 수 있습니다. 기본값은 black입니다.",
            "type" : "object",
            "properties" : {
                "color" : {
                    "type" : "string",
                    "default" : "black"
                },
                "style" : {
                    "$ref" : "#/definitions/LineStyle",
                    "default" : "LineStyle.empty"
                }
            }
        }
        ```

        "LineBorder"의 JSON 데이터를 검증하려면 완전한 "LineBorder" JSON Schema를 사용해야 합니다.

        ```json
         {
            "title" : "LineBorder",
            "description" : "테두리 선의 색상을 나타냅니다. 알려진 색상 이름 또는 HEX 스타일 색상 값을 사용할 수 있습니다. 기본값은 black입니다.",
            "type" : "object",
            "properties" : {
                "color" : {
                    "type" : "string",
                    "default" : "black"
                },
                "style" : {
                    "$ref" : "#/definitions/LineStyle",
                    "default" : "LineStyle.empty"
                }
            },
            "definitions":{
                "LineStyle":{
                   "title":"LineStyle",
                   "description":"테두리에 사용할 선 그리기 스타일을 지정합니다. empty:0, thin:1, medium:2, dashed:3, dotted:4, thick:5, double:6, hair:7, mediumDashed:8, dashDot:9, mediumDashDot:10, dashDotDot:11, mediumDashDotDot:12, slantedDashDot:13.",
                   "enum":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
                }
            }
        }
        ```
2. 전체 JSON 데이터 검증하기
    SpreadJS 전체 버전 JSON 데이터를 검증하려면 전체 버전 JSON Schema를 사용할 수 있습니다.