자동 패킷 생성 스크립트로 json을 이용 하여 개발중인데..

json 키값이 잘못 되면 생성 할때 어느줄에서 에러나는지 만들었지만...

스크립트 생성전에 뭔가 체크 할께 없을까 했는데..

vs에서 json 파일 열면 스키마를 세팅 해서 규격에 맞게 작성 할수 있는 기능이 있더라구요..


사용법은 위 동영상을 보면 될꺼 같네요..


하지만 저걸로 끝이면 뭐 정리를 할 필요가 없었겠죠...


{
"title": "value",
"list" : [
{
"name" : "test",
"values" : [
{
"value1": 100,
"value2": 200
},
{
"value1": 300,
"value2": 400
}
]
}
]
}


간단하게 위와 같이 list array에 values array 가 들어있는 구조 임다..


https://www.liquid-technologies.com/online-json-to-schema-converter


위 주소로 json을 가지고 가면 아래와 같이 머싯게 뽑아주긴 합니다.


{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"values": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"value1": {
"type": "integer"
},
"value2": {
"type": "integer"
}
},
"required": [
"value1",
"value2"
]
},
{
"type": "object",
"properties": {
"value1": {
"type": "integer"
},
"value2": {
"type": "integer"
}
},
"required": [
"value1",
"value2"
]
}
]
}
},
"required": [
"name",
"values"
]
}
]
}
},
"required": [
"title",
"list"
]
}


하지만 여기 함정이 있더군요..

위 사이트는 고정 적인 값만 체크 하게 되는 문제가 있더라구요

예를 들면 list array에 object를 추가 하면 두번째 부터는 자동으로 값이 안튀어나오는...


그래서 최소한 구조만 넣고 다시 뽑아야 합니다.

그리고 "items" 부분에 있는 대괄호를 ([]) 제거 해줘야 합니다.

대괄호가 있으니 1개만 인식 하는 문제가 있습니다..


{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"values": {
"type": "array",
"items": {
"type": "object",
"properties": {
"value1": {
"type": "integer"
},
"value2": {
"type": "integer"
}
},
"required": [
"value1",
"value2"
]
}
}
},
"required": [
"name",
"values"
]
}
}
},
"required": [
"title",
"list"
]


위에는 최소한의 값만 세팅해서 뽑고 items에 있는 대괄호를 수동 제거 한 상태

(하지만 테스트는 안해봤다는거...)


위 파일 저장 하고 동영상에 나온데로 하면 ctrl + 스페이스 누르면 각 상황에 맞는 key값이 나오는것을

확인 할 수 있습니다.


흠... 그리고 또 하나의 팁을 드리자면..


"description": key 값을 추가하면 각 키의 설명을 달수 있습니다..

그거 달아두면 뭐 팝업으로 설명 나오니...


더 자세한건 인터넷에 많으니 구글에게 물어보시면 됩니다..



by 널부러 2018. 7. 21. 00:01
| 1 |