items : Schema | Array<Schema>
items
Schema | Array<Schema>If set to a schema, validation succeeds if each element of the instance validates against it, otherwise validation succeeds if each element of the instance validates against the schema at the same position, if any
| Value |
This keyword must be set to a valid JSON Schema or to a non-empty array, where each item is a valid JSON Schema
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
|---|---|
| Kind | Applicator Annotation |
| Applies To | Array |
| Base Dialect | 2019-09 |
| Changed In | Draft 6 |
| Introduced In | Draft 1 |
| Vocabulary | Applicator |
| Specification | https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.9.3.1.1 |
| Metaschema | https://json-schema.org/draft/2019-09/meta/applicator |
| Official Tests | draft2019-09/items.json |
| Default |
{}
|
| Annotation |
Number
Boolean
If set to a schema, a boolean true if it applied to every item of the instance, otherwise the largest index to which this keyword applied its subschema, or a boolean true if it was applied to every item of the instance
Hint: Use the jsonschema validate command to collect annotations from the command-line
|
| Affected By |
|
| Affects |
|
| Also See |
|
The items keyword is used to
validate array items and has two different modes of operation depending on the
type of its value:
-
Schema: When set to a schema,
itemsvalidates that all items in the array instance validate against the given subschema. Whether this keyword was evaluated against any item of the array instance is reported using annotations. -
Array: When set to an array of schemas,
itemsvalidates each item in the array instance against the subschema at the corresponding position. Items beyond the length of theitemsarray can be validated using theadditionalItemskeyword. The annotation reports the largest index to which a subschema was applied, ortrueif it was applied to every item.
Common Pitfall
This keyword does not prevent an array instance from being
empty. If needed, use the minItems to assert on the minimum bounds of the array.
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
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"items": { "type": "number" }
}[ 1, -3.4, 54 ]{ "keyword": "/items", "instance": "", "value": true }[][ 1, -3.4, 54, "foo" ]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"items": [ { "type": "boolean" }, { "type": "number" } ]
}[ false, 35 ]{ "keyword": "/items", "instance": "", "value": true }[ false, 35, "foo", "bar" ]{ "keyword": "/items", "instance": "", "value": 1 }[ "not a boolean", 35 ][ false, "not a number" ][]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"items": [ { "type": "boolean" }, { "type": "number" } ],
"additionalItems": { "type": "string" }
}[ false, 35 ]{ "keyword": "/items", "instance": "", "value": true }[ false, 35, "foo", "bar" ]{ "keyword": "/items", "instance": "", "value": 1 }
{ "keyword": "/additionalItems", "instance": "", "value": true }[ false, 35, { "foo": "bar" } ][]"Hello World"