Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading