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
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-07/schema#",
"items": { "type": "number" }
}[ 1, -3.4, 54 ][][ 1, -3.4, 54, "foo" ]"Hello World"{
"$schema": "http://json-schema.org/draft-07/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-07/schema#",
"items": [ { "type": "boolean" }, { "type": "number" } ],
"additionalItems": { "type": "string" }
}[ false, 35 ][ false, 35, "foo", "bar" ][ false, 35, { "foo": "bar" } ][]"Hello World"