我是JSON Schema Validator的完全新手,但我认为它非常强大。但是,我只是无法验证一个JSON。NodeJS JSON模式验证不起作用
这是我的架构
{
title: "Example Schema",
type: "object",
properties: {
original_image:{
type: "object",
properties: {
temp_id: {type: "string"},
url: {type: "string"},
scale:{
type: "object",
properties:{
new_width: {type: "number"},
new_height: {type: "number"}
},
required:["new_width","new_height"]
}
},
required:["url","temp_id","scale"]
}
},
required:["image"]
}
这是实际的JSON:
{
"original_image": {
"temp_id": "this is my id",
"scale": {
"new_width": null,
"new_height": 329
}
}
}
所以你可以从“original_image”看到“URL”属性是不存在的,但验证返回true!而且,对于“new_width”,我将该值设置为null ...并再次通过验证,因此我不知道我在做什么错误。
我正在使用json-schema,破折号,但没有它的jsonschema看起来很好。所以我想我会切换到“jsonschema”包,工作! –