unevaluatedItems : Schema
unevaluatedItems
SchemaValidates array elements that did not successfully validate against other standard array applicators.
| Value |
This keyword must be set to 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 | None |
| Introduced In | 2019-09 |
| Vocabulary | Applicator |
| Specification | https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.9.3.1.3 |
| Metaschema | https://json-schema.org/draft/2019-09/meta/applicator |
| Official Tests | draft2019-09/unevaluatedItems.json |
| Default |
{}
|
| Annotation |
Boolean
A boolean true if it applied to any item of the instance
Hint: Use the jsonschema validate command to collect annotations from the command-line
|
| Affected By |
|
| Affects | None |
| Also See |
|
The unevaluatedItems
keyword is a generalisation of the additionalItems keyword that considers related
keywords even when they are not direct siblings of this keyword. More
specifically, this keyword is affected by occurrences of items, additionalItems, and unevaluatedItems itself, as long as the evaluate path
that led to unevaluatedItems is a prefix of the evaluate path of the others.
Given its evaluation-dependent nature, this keyword is evaluated after every other keyword from every other vocabulary.
Best Practice
There are two common use cases for this keyword, both for reducing duplication:
(1) Elegantly describing additional array items while declaring the
items or additionalItems keywords behind conditional logic
without duplicating these keywords in every possible branch. (2) Reusing
helpers that consist of the items
or additionalItems
keywords, while specialising the helpers as needed in specific locations
without having to inline the entire contents of the helper.
Digging Deeper
The JSON Schema specification defines the relationship between this keyword and the ones that affect it in terms of annotations. However, in practice, most implementations avoid the use of annotations for performance reasons, as emitting annotations and checking the annotation values of other keywords often involves significant memory allocation and complex data structure traversals.
The paper Elimination of annotation dependencies in validation for Modern JSON Schema is a comprehensive mathematical study of how applicators can be automatically re-written to avoid annotation dependencies, leading to schemas that are simpler to evaluate.
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",
"if": { "maxItems": 3 },
"then": { "items": [ { "type": "string" } ] },
"else": { "items": { "type": "boolean" } },
"unevaluatedItems": { "type": "number" }
}[ "foo", 1, 2 ]{ "keyword": "/then/items", "instance": "", "value": 0 }
{ "keyword": "/unevaluatedItems", "instance": "", "value": true }[ true, false, true ]{ "keyword": "/else/items", "instance": "", "value": true }[ "foo", "bar", "baz" ][ true, 2, false ][]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$ref": "#/$defs/string-first-item",
"unevaluatedItems": false,
"$defs": {
"string-first-item": {
"items": [ { "type": "string" } ]
}
}
}[ "foo" ]{ "keyword": "/$defs/string-first-item/items", "instance": "", "value": 0 }[ "foo", 2, 3 ][]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "items": true },
{ "unevaluatedItems": false }
]
}[ 1, 2, 3 ][]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [ { "unevaluatedItems": true } ],
"unevaluatedItems": false
}[ 1, 2, 3 ]{ "keyword": "/allOf/0/unevaluatedItems", "instance": "", "value": true }[]"Hello World"