Search code examples
jsonjsonschema

Confusion over some JSON Schema Validation


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




Solution

  • Your schema has interfacename under properties instead of Interface1.