JSON-schema 表示 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 架构网站上的示例似乎都没有声明这一点,因此我怀疑不应该声明它。但我还是很好奇:)
最佳答案
建议在 JSON 模式中使用 $schema
关键字,以表示正在使用的模式标准的版本。
但是,它在数据中没有特殊含义。通过 HTTP,有 recommended ways将数据与架构关联起来,但 $schema
属性不是其中之一。
关于json - JSON 模式是否应该要求文档声明 `$schema`(自引用)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26494535/