【发布时间】:2017-05-08 17:30:14
【问题描述】:
我想要验证以下 JSON 数据。
[
{ "fieldType": "oneThing" },
{ "fieldType": "anotherThing" },
{ "fieldType": "oneThing" }
]
我当前(非工作)架构是:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"oneOf": [
{ "$ref": "#/definitions/oneThing" },
{ "$ref": "#/definitions/anotherThing" }
]
},
"definitions": {
"oneThing": {
"type": "object",
"properties": {
"fieldType": {
"type": "string",
"pattern": "oneThing"
}
},
"required": [
"fieldType"
]
},
"anotherThing": {
"type": "object",
"properties": {
"fieldType": {
"type": "string",
"pattern": "anotherThing"
}
},
"required": [
"fieldType"
]
}
}
}
我收到以下错误,但我看不到我做错了什么。
[] Object value found, but an array is required
更多上下文:我正在生成一个基于 JSON 配置的动态 HTML 表单。 HTML 表单将具有一组特定的有效字段类型,并且相同的字段类型可能在配置中存在多次,因此oneThing 在上述示例 json 中出现多次。
【问题讨论】:
标签: json jsonschema json-schema-validator