Skip to content

Commit a803229

Browse files
committed
added section about array indexing
1 parent c4953f1 commit a803229

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

jsonschema-core.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,12 @@ results.
16331633

16341634
#### Keywords for Applying Subschemas to Arrays
16351635

1636+
##### Indexing Arrays {#array-index}
1637+
1638+
When working with arrays and indices, JSON Schema uses zero-based indexing. This
1639+
aligns with both JSON's JavaScript heritage and its usage of JSON Pointer for
1640+
references and annotations.
1641+
16361642
##### `prefixItems`
16371643

16381644
The value of `prefixItems` MUST be a non-empty array of valid JSON Schemas.
@@ -1657,20 +1663,20 @@ The value of `items` MUST be a valid JSON Schema.
16571663
This keyword ignores elements in the instance array equal to the number of
16581664
subschemas found in the `prefixItems` array in the same schema object, starting
16591665
from the beginning of the instance array. It then applies its subschema to
1660-
remaining instance elements. If `prefixItems` does not exist within the same
1661-
schema object, `items` applies its subschema to all instance array elements.
1666+
remaining elements.
1667+
1668+
If `prefixItems` contains more subschemas than the number of elements in the
1669+
instance array, `items` applies its subschema to no elements.
1670+
1671+
If `prefixItems` does not exist within the same schema object, `items` applies
1672+
its subschema to all elements.
16621673

16631674
If the `items` subschema is applied to any positions within the instance array,
16641675
it produces an annotation result of boolean true, indicating that all remaining
16651676
array elements have been evaluated against this keyword's subschema.
16661677

16671678
Omitting this keyword has the same assertion behavior as an empty schema.
16681679

1669-
Implementations MAY choose to implement or optimize this keyword in another way
1670-
that produces the same effect, such as by directly checking for the presence and
1671-
size of a `prefixItems` array. Implementations that do not support annotation
1672-
collection MUST do so.
1673-
16741680
The presence of this keyword affects the behavior of
16751681
[`unevaluatedItems`](#unevaluateditems).
16761682

@@ -1712,7 +1718,8 @@ The annotation result of this keyword is the set of instance property names
17121718
matched by at least one property under this keyword.
17131719

17141720
The presence of this keyword affects the behaviors of
1715-
[`additionalProperties`(#additionalproperties) and [`unevaluatedProperties`](#unevaluatedproperties).
1721+
[`additionalProperties`(#additionalproperties) and
1722+
[`unevaluatedProperties`](#unevaluatedproperties).
17161723

17171724
##### `additionalProperties` {#additionalproperties}
17181725

@@ -1789,12 +1796,12 @@ The minimum number of occurrences is provided by the `minContains` keyword
17891796
within the same schema object as `contains`. If `minContains` is absent, the
17901797
minimum number of occurrences MUST be 1.
17911798

1792-
This keyword produces an annotation value which is an array of the indices for
1793-
which this keyword validates successfully when applying its subschema, in
1794-
ascending order. The value MAY be a boolean `true` if the subschema validates
1795-
successfully when applied to every index of the instance. The annotation MUST be
1796-
present if the instance array to which this keyword's schema applies
1797-
is empty.
1799+
This keyword produces an annotation value which is an array of the zero-based
1800+
indices for which this keyword validates successfully when applying its
1801+
subschema, in ascending order. The value MAY be a boolean `true` if the
1802+
subschema validates successfully when applied to every index of the instance.
1803+
The annotation MUST be present if the instance array to which this keyword's
1804+
schema applies is empty.
17981805

17991806
The presence of this keyword affects the behavior of
18001807
[`unevaluatedItems`](#unevaluateditems).

0 commit comments

Comments
 (0)