items : Schema

items

Schema

Validation succeeds if each element of the instance not covered by prefixItems validates against this schema.

Value This keyword must be set to a valid JSON Schema
Kind Applicator Annotation
Applies To Array
Dialect 2020-12
Changed In 2019-09 Draft 6
Introduced In Draft 1
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.3.1.2
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/items.json
Default {}
Annotation Boolean A boolean true if it applied to any item of the instance
Affected By
Affects
Also See

The items keyword is used to validate arrays of arbitrary length where each item in the array matches the same schema. It applies its subschema to all instance items at indexes greater than the length of the prefixItems array in the same schema, or to all instance array elements if prefixItems is not present. This means that the subschema specified under items will be used to validate every item in the array that isn’t covered by prefixItems.

If the items subschema is applied to any positions within the instance array, it produces an annotation result of boolean true, indicating that all remaining array elements have been evaluated against this keyword’s subschema. This annotation affects the behavior of unevaluatedItems in the Unevaluated vocabulary.

  • prefixItems allows defining a fixed-length sequence of schemas for an array’s initial items.
  • items applies its sub-schema to all elements after the prefixItems sequence (if present).
  • Analogous to additionalProperties for objects, items specifies a schema that each item in the array must adhere to. If an array has additional items beyond what’s defined in prefixItems, they must conform to the schema specified under items.

Examples

Schema with 'items' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": { "type": "number" }
}
Valid An array instance with all items as numeric values is valid Instance
[ 2, 3, 44, -5 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Invalid An array instance containing a string value is invalid Instance
[ 2, 3, "44", -5 ]
Schema with 'items' set to boolean true Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": true
}
Valid An array instance with all items as numeric values is valid Instance
[ 2, 3, 44, -5 ]
Valid An array instance containing a string value is also valid Instance
[ 2, 3, "44", -5 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
  • Similarly, if the items is set to false, all the array instances will fail validation.
Schema with 'items' and 'prefixItems' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "prefixItems": [
    { "type": "boolean" },
    { "type": "string" }
  ],
  "items": { "type": "number" }
}
Valid An array instance adhering to the schema is valid Instance
[ false, "44", -5 ]
Annotations
{ "keyword": "/prefixItems", "instance": "", "value": 1 }
{ "keyword": "/items", "instance": "", "value": true }
Invalid The prefix items of the array instance must adhere to the subschemas in 'prefixItems' at their respective indexes Instance
[ 2, 3, "44", -5 ]