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 |
| Applies To | Array |
| Base Dialect | Draft 6 |
| Changed In | 2020-12 |
| Introduced In | Draft 1 |
| Vocabulary | Validation |
| Specification | https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.6.9 |
| Metaschema | http://json-schema.org/draft-06/schema# |
| Official Tests | draft6/items.json |
| Default |
{}
|
| Annotation | None |
| 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. -
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.
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": "http://json-schema.org/draft-06/schema#",
"items": { "type": "number" }
}[ 1, -3.4, 54 ][][ 1, -3.4, 54, "foo" ]"Hello World"{
"$schema": "http://json-schema.org/draft-06/schema#",
"items": [ { "type": "boolean" }, { "type": "number" } ]
}[ false, 35 ][ false, 35, "foo", "bar" ][ "not a boolean", 35 ][ false, "not a number" ][]"Hello World"{
"$schema": "http://json-schema.org/draft-06/schema#",
"items": [ { "type": "boolean" }, { "type": "number" } ],
"additionalItems": { "type": "string" }
}[ false, 35 ][ false, 35, "foo", "bar" ][ false, 35, { "foo": "bar" } ][]"Hello World"