我正在尝试学习一些关于 json 的知识。我使用 npm 安装了 jsonlint。我从这个网站完全复制了一个模式和一个文件。它们如下:
测试.json:
[
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}
]
模式.json:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
},
"required": ["length", "width", "height"]
},
"warehouseLocation": {
"description": "Coordinates of the warehouse with the product",
"$ref": "http://json-schema.org/geo"
}
},
"required": ["id", "name", "price"]
}
}
我将这两个文件都保存在同一个目录中。我输入了以下命令。
jsonlint test.json --validate schema.json
并收到以下输出:
验证错误:
Instance is not a required type
uri: urn:uuid:67449791-6ef0-4a5f-8ee1-d9ae1c806249#/items
schemaUri: http://json-schema.org/draft-03/hyper-schema#/properties/items
attribute: type
details: ["http://json-schema.org/draft-03/hyper-schema#","array"]
当我在本网站的验证器中输入完全相同的代码时, 它检查为有效。
当我故意通过删除一个 id(这是必需的)来破坏我的 json 文件时,我收到了完全相同的输出。
为什么会发生这种情况?我该如何解决?