I have now spent more than a few hours on this issue and I felt that it was time to reach out for some assistance because clearly I am missing some fundamental concepts about JSON schema validation that I thought I understood.
Here’s some JSON that I actually expect not to pass the validation of some schema I created:
{
"requests": {
"Interface1": [
{
"foo": "bar",
"id": 9999,
"text": "foo"
}
]
}
}
Why is the above JSON being considered as OK by the following schema when I clearly indicate that additionalProperties is False and I list "foo" and "id" as required property names in each nested object of the array:
{
"type": "object",
"properties": {
"requests": {
"type": "object",
"properties": {
"interfacename": {
"type": "array",
"items": {
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"id": {
"type": "number"
}
},
"required": [
"foo",
"id"
],
"additionalProperties": false
}
}
},
"required": [
"Interface1"
]
}
}
}
2
Answers
Your schema has
interfacename
underproperties
instead ofInterface1
.Yes, you just need to change the name of the property "interfacename" to "Interface1", or change the required field "Interface1" to "interfacename".
For the sample file your schema be something like this: