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
Base 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 restricts array instance items not described by the prefixItems keyword (if any), to validate against the given subschema. Whether this keyword was evaluated against any item of the array instance is reported using annotations.

Remember that JSON Schema is a constraint-driven language. Therefore, non-array instances successfully validate against this keyword. If needed, make use of the type keyword to constraint the accepted type accordingly.

Examples

A schema that constrains array instances to consist of number items Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "items": { "type": "number" }
}
Valid An array value that only consists of number items is valid Instance
[ 1, -3.4, 54 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Valid An empty array value is valid Instance
[]
Invalid An array value that includes a non-number item is invalid Instance
[ 1, -3.4, 54, "foo" ]
Valid A non-array value is valid Instance
"Hello World"
A schema that constrains array instances to start with a boolean item followed by a number item followed by strings Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "prefixItems": [ { "type": "boolean" }, { "type": "number" } ],
  "items": { "type": "string" }
}
Valid An array value that consists of a boolean item followed by a number item is valid Instance
[ false, 35 ]
Annotations
{ "keyword": "/prefixItems", "instance": "", "value": true }
Valid An array value that consists of a boolean item followed by a number item and other string items is valid Instance
[ false, 35, "foo", "bar" ]
Annotations
{ "keyword": "/prefixItems", "instance": "", "value": 2 }
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Invalid An array value that consists of a boolean item followed by a number item and other non-string items is invalid Instance
[ false, 35, { "foo": "bar" } ]
Valid An empty array value is valid Instance
[]
Valid A non-array value is valid Instance
"Hello World"