additionalItems and items - sgpinkus/json-schema GitHub Wiki

THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.


NOTE: This proposal was incorporated into Draft 04


Description

The validity of an array instance with regards to these keywords is determined as follows:

  • if items is not present, or its value is an object, validation of the instance always succeeds, regardless of the value of additionalItems;
  • if the value of additionalItems is boolean value true or an object, validation of the instance always succeeds;
  • if the value of additionalItems is boolean value false and the value of items is an array (which is must be at this point, see below), the instance is valid if and only if its number of elements is less than, or equal to, the number of elements in the array value of items.

Valid values

The value of additionalItems MUST be either a boolean or an object. If it is an object, this object MUST be a valid JSON Schema. Boolean value true MAY be considered equivalent to an empty schema.

The item keyword's value MUST be either an object or an array.

If it is an object, this object MUST be a valid JSON Schema.

If it is an array, elements of this array MUST be objects, and each of these objects MUST be a valid JSON Schema.

Example

This example covers the case where additionalItems is false and items is an array of schemas, since this is the only case where validation of an array instance may fail.

Given this schema:

{
    "items": [ {}, {}, {} ],
    "additionalItems": false
}

the following instances are valid:

  • [ 1, 2, 3 ];
  • [ { "gloubi": "boulga" }, null ];
  • [];

the following instances are invalid:

  • [ "this", "array", "has", "too", "many", "elements" ];
  • [ 1, 2, 3, 4 ];
  • [ true, false, null, [ "a", "b", 32 ] ].
⚠️ **GitHub.com Fallback** ⚠️