I've seen this other question but it's not quite the same, and I feel like my issue is simpler, but just isn't working.
我的数据如下所示:
[
{ "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"},
{ "loc": "a value 2", "toll" : "toll is sometimes null", "message" : null}
]
我想在一个 node 中使用AJV进行JSON验证.js项目,我try 了几种模式来描述我的数据,但我总是得到这样的错误:
[ { keyword: 'type',
dataPath: '',
schemaPath: '#/type',
params: { type: 'array' },
message: 'should be array' } ]
The schema I've tried looks like this:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"loc": {
"type": "string"
},
"toll": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"loc"
]
}
}
我还try 使用this online tool生成模式,但这也不起作用,为了验证它是否应该输出正确的结果,我try 使用jsonschemavalidator.net验证该输出,但这也给了我一个类似的错误:
Found 1 error(s)
Message:
Invalid type. Expected Array but got Object.
Schema path:
#/type