2014-10-21 1 views
2

JSON 스키마는 JSON 문서가 the $schema property을 사용하여 문서가 준수하는 스키마를 선언 할 수 있다고 말합니다. 예 : 스키마가 보이는

{ 
    "$schema": "http://example.com/example_fancy_schema#", 
    "example_fancy_property": "cute fluffy kittens" 
} 

:

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Example Fancy Schema", 
    "description": "The schema that describes the example format.", 
    "type": "object", 
    "properties": { 
     "example_fancy_property": { 
      "type": "string", 
      "enum": ["cute fluffy kittens"] 
     } 
    }, 
    "additionalProperties": false, 
    "required": [ "example_fancy_property" ] 
} 

이 하나, 실제 스키마에서 이것에 대한 속성을 추가해야한다는 뜻 예 :의

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Example Fancy Schema", 
    "description": "The schema that describes the example format.", 
    "type": "object", 
    "properties": { 
     "$schema": { 
      "type": "string", 
      "enum": ["http://example.com/example_fancy_schema#"] 
     }, 
     "example_fancy_property": { 
      "type": "string", 
      "enum": ["cute fluffy kittens"] 
     } 
    }, 
    "additionalProperties": false, 
    "required": [ "$schema", "example_fancy_property" ] 
} 

없음 JSON 스키마 웹 사이트의 예제에서이를 선언 한 것으로 보이므로이를 선언하지 않아도된다고 생각됩니다. 하지만 어쨌든 궁금 :)

답변

3

$schema 키워드 JSON 스키마에 사용 권장 이다가, 스키마 표준의 버전을 사용하고 표시하기 위해.

그러나 데이터에는이라는 특별한 의미가 없습니다. HTTP를 통해 recommended ways이 스키마와 데이터를 연결하지만 $schema 속성은 그 중 하나가 아닙니다.

+0

아, 맞아. 스펙을 다시 보면 나는 처음에 그 생각을 어디에서 얻었는지 확신 할 수 없다. 실제 json 문서에서이를 선언 할 수있는 방법이 없다는 것은 너무 나쁩니다. –

+0

예 - 데이터에서'$ schema'와 같은 규칙은 매우 좋습니다. 아쉽게도 JSON 스키마 사양에는 모든 JSON 문서에서 속성 이름을 예약 할 수있는 권한이 없습니다. – cloudfeet

+0

그러한 참조는 권고 사항 일 뿐이므로 그렇게하지 않아도됩니다. 예 : 그것은 어떤 스키마를 사용할 것인가를 에디터에게 제안하는 것이지 클라이언트가 상기 스키마를 따르지 않는 문서를 거부 할 필요는 없다. 오 잘 :) –