In using https://www.jsonschemavalidator.net/
I have a schema of:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Product",
"description": "A product from Acmes catalog",
"type": "object",
"additionalProperties": false,
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"birthday": {
"type": "string",
"format": "date-time"
},
"category": {
"type": "string",
"enum": [
"Driver Qual",
"Medical Info",
"Personel",
"Personnel",
"Prev Emp Inquiry",
"Drug-Alcohol"
]
},
"address": {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"country": {
"type": "string"
}
}
}
},
"required": [
"first_name",
"last_name"
]
}
and a json file that is:
{
"first_name": "George",
"last_name": "Washington",
"birthday": "2018-11-13T20:20:39+00:00",
"address": {
"street_address": "3200 Mount Vernon Memorial Highway",
"city": "Mount Vernon",
"state": "Virginia",
"country": "United States",
"category": "Personel2"
}
}
this passes validation, but if I change the json file to: ( i.e. move the location of category to under birthday ) it fails ( as I would expect being Personel2 is not in the enum list )
{
"first_name": "George",
"last_name": "Washington",
"birthday": "2018-11-13T20:20:39+00:00",
"category": "Personel2",
"address": {
"street_address": "3200 Mount Vernon Memorial Highway",
"city": "Mount Vernon",
"state": "Virginia",
"country": "United States"
}
}
Why does it not fail when the category is at the end of the file ? I thought the order of the properties is irrelevant ?