我已经看到了另一个问题,但它并不完全相同,我觉得我的问题更简单,但只是不起作用。
我的数据看起来像这样:
[
{ "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"},
{ "loc": "a value 2", "toll" : "toll is sometimes null", "message" : null}
]
我想在 Node.js 项目中使用AJV进行 JSON 验证,我尝试了几种模式来尝试描述我的数据,但我总是将其视为错误:
[ { keyword: 'type',
dataPath: '',
schemaPath: '#/type',
params: { type: 'array' },
message: 'should be array' } ]
我尝试过的架构如下所示:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"loc": {
"type": "string"
},
"toll": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"loc"
]
}
}
我还尝试使用此在线工具生成模式,但这也不起作用,为了验证应该输出正确的结果,我尝试针对jsonschemavalidator.net验证该输出,但这也给了我一个类似的错误:
Found 1 error(s)
Message:
Invalid type. Expected Array but got Object.
Schema path:
#/type