Determining what schema an array element should validate against - sgpinkus/json-schema GitHub Wiki

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


NOTE: This algorithm was included in Draft 04. Adding the more verbose wording to the web site is tracked at https://github.com/json-schema-org/json-schema-org.github.io/issues/25


Implied keywords

For one array element, the schema which this element must validate against depends on its index in the array and the following keywords:

  • items,
  • additionalItems.

NOTE: array indices start at 0.

If items is absent

If items is absent, its default value is the empty schema. Which means all elements are valid. The end ;)

If items is an object

In this case, all elements of the array instance MUST be valid against the items keyword value, which is a JSON Schema.

Otherwise: items is an array

If this is an array, then the schema is determined by the index of the array element to validate. There are two possibilities:

The element index is less than, or equal to, the highest index in the items array

In this case, the element MUST be valid against the schema found at the given index in the items array.

The element index is greater than the highest index in the items array

In this case, it depends on the value of additionalItems:

If additionalItems is boolean true, or absent

This is equivalent to additionalItems being an empty schema, which means the element always validates successfully.

If additionalItems is an object

If it is an object, then by the rules, it is a valid JSON Schema. In this case, the element MUST validate successfully against that schema.

⚠️ **GitHub.com Fallback** ⚠️