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 |
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.
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/2020-12/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/2020-12/schema",
"prefixItems": [ { "type": "boolean" }, { "type": "number" } ],
"items": { "type": "string" }
}
[ false, 35 ]
{ "keyword": "/prefixItems", "instance": "", "value": true }
[ false, 35, "foo", "bar" ]
{ "keyword": "/prefixItems", "instance": "", "value": 2 }
{ "keyword": "/items", "instance": "", "value": true }
[ false, 35, { "foo": "bar" } ]
[]
"Hello World"