prefixItems : Array<Schema>
prefixItems
Array<Schema>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 non-empty array, where each item is a valid JSON Schema |
---|---|
Kind | Applicator Annotation |
Applies To | Array |
Dialect | 2020-12 |
Changed In | None |
Introduced In | 2020-12 |
Vocabulary | Applicator |
Specification | https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.3.1.1 |
Metaschema | https://json-schema.org/draft/2020-12/meta/applicator |
Official Tests | draft2020-12/prefixItems.json |
Default |
As if it was set to the (invalid) value:
[]
|
Annotation | Number Boolean The largest index to which this keyword applied its subschema, or a boolean true if it was applied to every item of the instance |
Affected By | None |
Affects |
|
Also See |
|
The prefixItems
keyword is used to validate arrays by applying a schema to each corresponding index of the array. It differs from the items
keyword in that it validates only a prefix of the array, up to the length of the prefixItems
array. Each schema specified in prefixItems
corresponds to an index in the input array.
- The annotation produced by this keyword affects the behavior of
items
andunevaluatedItems
. items
is used to validate all items in an array that are not covered byprefixItems
, whileprefixItems
validates only a prefix of the array.prefixItems
keyword does not constrain the length of the array. If the array is longer than this keyword’s value, this keyword validates only the prefix of matching length.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [ { "type": "number" } ]
}
[ 2, false ]
{ "keyword": "/prefixItems", "instance": "", "value": 0 }
[ "2", 3 ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [
{ "type": "boolean" },
{ "type": "number" }
]
}
[ false, 35, [ "foo" ] ]
{ "keyword": "/prefixItems", "instance": "", "value": 1 }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [
{ "type": "boolean" },
{ "type": "string" }
],
"items": { "type": "number" }
}
[ false, "44", -5 ]
{ "keyword": "/prefixItems", "instance": "", "value": 1 }
{ "keyword": "/items", "instance": "", "value": true }
[ 2, 3, "44", -5 ]