items : Schema
items
SchemaValidation 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 theprefixItems
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 inprefixItems
, they must conform to the schema specified underitems
.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": { "type": "number" }
}
[ 2, 3, 44, -5 ]
{ "keyword": "/items", "instance": "", "value": true }
[ 2, 3, "44", -5 ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": true
}
[ 2, 3, 44, -5 ]
[ 2, 3, "44", -5 ]
{ "keyword": "/items", "instance": "", "value": true }
- Similarly, if the
items
is set to false, all the array instances will fail validation.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [
{ "type": "boolean" },
{ "type": "string" }
],
"items": { "type": "number" }
}
[ false, "44", -5 ]
{ "keyword": "/prefixItems", "instance": "", "value": 1 }
{ "keyword": "/items", "instance": "", "value": true }
[ 2, 3, "44", -5 ]