1

I am creating a JSON schema and want to define an array containing only exact matches for certain items:

An example of the sort of JSON (snippet) would look like:

{
   "results":
   [
       { "id": 1, "test": true, "volts": 700, "duration": 100 },
       { "id": 2, "test": false }
   ]
}

This seems to be a combination of OneOf and "additionalProperties": false but I can't work out how that should be used. So far I have:

{
  "results": 
  {
    "type": "array",
    "items": 
    {
      "type": "object",
      "OneOf": 
      [
        {
          "id":    { "type": "integer" },
          "test":  { "type": "boolean" },
          "volts": { "type": "integer" },
          "duration": { "type": "integer" }
        },
        {
          "id":    { "type": "integer" },
          "test":  { "type": "boolean" }
        }
      ],
      "additionalProperties": false          
    }
  }
}

I'm using http://www.jsonschemavalidator.net/ to check my JSON.

But when I validate the following JSON against my schema it says it's valid; is the website incorrect or have I done something wrong?

{
  "results": [
    {
      "fred": 7,
      "id": 7,
      "test": true,
      "volts": 7,
      "duration": 7
    },
    {
      "fish": 7
    }
  ]
}
Rob
  • 335
  • 8
  • 23
  • Possible duplicate of [Regex describing a regex pattern?](http://stackoverflow.com/questions/37535865/regex-describing-a-regex-pattern) – Paul Sweatte Sep 11 '16 at 06:07

0 Answers0