【发布时间】:2021-12-19 10:07:51
【问题描述】:
是否可以定义 JSON 模式来检查内部数据完整性?这样"ba" 之类的错误就可以在没有进一步运行时检查的情况下被检测到。
数据 JSON
{
"childNames": ["foo", "bar", "baz"],
"children": [
{
"name": "foo"
},
{
"name": "ba"
}
]
}
JSON 架构
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://tbd.com/foo/bar",
"type": "object",
"properties": {
"childNames": {
"type": "array",
"items": { "type": "string" }
},
"children": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"enum": { "$ref": "???" }
}
}
}
}
}
}
【问题讨论】:
标签: json schema jsonschema