简体   繁体   中英

jsonlint schema not validating

I am trying to learn a bit about json. I installed jsonlint using npm. I copied a schema and a file from this website exactly. They are as follows:

test.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
        }
    }
]

schema.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"]
    }
}

I have both of these files saved in the same directory. I entered the following command.

jsonlint test.json --validate schema.json

And received the following output:

Validation Errors:

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"]

When I entered the exact same code into the validator on this website it checked out as valid.

When I purposely break my json file by removing an id (which is required) I received the exact same output.

Why might this happen? How can I fix it?

它具有的其中一个依赖项(JSV)似乎没有问题,但没有引用该版本的草案04

jsonlint can't currently validate against a draft-04 schema. You have to create a schema using draft-03

See here for tools that validate against draft-04: http://json-schema.org/implementations.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM