@@ -1613,6 +1613,12 @@ results.
16131613
16141614#### Keywords for Applying Subschemas to Arrays
16151615
1616+ ##### Indexing Arrays {#array-index}
1617+
1618+ When working with arrays and indices, JSON Schema uses zero-based indexing. This
1619+ aligns with both JSON's JavaScript heritage and its usage of JSON Pointer for
1620+ references and annotations.
1621+
16161622##### ` prefixItems `
16171623
16181624The value of ` prefixItems ` MUST be a non-empty array of valid JSON Schemas.
@@ -1625,34 +1631,34 @@ and the instance value are affected by this keyword.
16251631This keyword produces an annotation value which is the largest index to which
16261632this keyword applied a subschema. The value MAY be a boolean true if a subschema
16271633was applied to every index of the instance, such as is produced by the ` items `
1628- keyword. This annotation affects the behavior of ` items ` and ` unevaluatedItems ` .
1634+ keyword.
1635+
1636+ The presence of this keyword affects the behaviors of [ ` items ` ] ( #items ) and
1637+ [ ` unevaluatedItems ` ] ( #unevaluateditems ) .
16291638
16301639##### ` items ` {#items}
16311640
16321641The value of ` items ` MUST be a valid JSON Schema.
16331642
1634- This keyword applies its subschema to all instance elements at indexes greater
1635- than the length of the ` prefixItems ` array in the same schema object, as
1636- reported by the annotation result of that ` prefixItems ` keyword. If no such
1637- annotation result exists, ` items ` applies its subschema to all instance array
1638- elements.[ ^ 11 ]
1643+ This keyword ignores elements in the instance array equal to the number of
1644+ subschemas found in the ` prefixItems ` array in the same schema object, starting
1645+ from the beginning of the instance array. It then applies its subschema to
1646+ remaining elements.
16391647
1640- [ ^ 11 ] : Note that the behavior of ` items ` without ` prefixItems ` is identical to
1641- that of the schema form of ` items ` in prior drafts. When ` prefixItems ` is
1642- present, the behavior of ` items ` is identical to the former ` additionalItems `
1643- keyword.
1648+ If ` prefixItems ` contains more subschemas than the number of elements in the
1649+ instance array, ` items ` applies its subschema to no elements.
1650+
1651+ If ` prefixItems ` does not exist within the same schema object, ` items ` applies
1652+ its subschema to all elements.
16441653
16451654If the ` items ` subschema is applied to any positions within the instance array,
16461655it produces an annotation result of boolean true, indicating that all remaining
1647- array elements have been evaluated against this keyword's subschema. This
1648- annotation affects the behavior of ` unevaluatedItems ` .
1656+ array elements have been evaluated against this keyword's subschema.
16491657
16501658Omitting this keyword has the same assertion behavior as an empty schema.
16511659
1652- Implementations MAY choose to implement or optimize this keyword in another way
1653- that produces the same effect, such as by directly checking for the presence and
1654- size of a ` prefixItems ` array. Implementations that do not support annotation
1655- collection MUST do so.
1660+ The presence of this keyword affects the behavior of
1661+ [ ` unevaluatedItems ` ] ( #unevaluateditems ) .
16561662
16571663#### Keywords for Applying Subschemas to Objects
16581664
@@ -1665,11 +1671,13 @@ Validation succeeds if, for each name that appears in both the instance and as a
16651671name within this keyword's value, the child instance for that name successfully
16661672validates against the corresponding schema.
16671673
1674+ Omitting this keyword has the same assertion behavior as an empty object.
1675+
16681676The annotation result of this keyword is the set of instance property names
1669- which are also present under this keyword. This annotation affects the behavior
1670- of ` additionalProperties ` and ` unevaluatedProperties ` .
1677+ which are also present under this keyword.
16711678
1672- Omitting this keyword has the same assertion behavior as an empty object.
1679+ The presence of this keyword affects the behaviors of
1680+ [ ` additionalProperties ` (#additionalProperties) and [ ` unevaluatedProperties ` ] ( #unevaluatedproperties ) .
16731681
16741682##### ` patternProperties `
16751683
@@ -1684,45 +1692,34 @@ instance for that name successfully validates against each schema that
16841692corresponds to a matching regular expression. Recall: regular expressions are
16851693not implicitly anchored.
16861694
1695+ Omitting this keyword has the same assertion behavior as an empty object.
1696+
16871697The annotation result of this keyword is the set of instance property names
1688- matched by at least one property under this keyword. This annotation affects the
1689- behavior of ` additionalProperties ` and ` unevaluatedProperties ` .
1698+ matched by at least one property under this keyword.
16901699
1691- Omitting this keyword has the same assertion behavior as an empty object.
1700+ The presence of this keyword affects the behaviors of
1701+ [ ` additionalProperties ` (#additionalproperties) and
1702+ [ ` unevaluatedProperties ` ] ( #unevaluatedproperties ) .
16921703
16931704##### ` additionalProperties ` {#additionalproperties}
16941705
16951706The value of ` additionalProperties ` MUST be a valid JSON Schema.
16961707
1697- The behavior of this keyword depends on the presence and annotation results of
1698- ` properties ` and ` patternProperties ` within the same schema object. Validation
1699- with ` additionalProperties ` applies only to the child values of instance names
1700- that do not appear in the annotation results of either ` properties ` or
1701- ` patternProperties ` .
1708+ The behavior of this keyword depends on the presence of ` properties ` and
1709+ ` patternProperties ` within the same schema object. Validation with
1710+ ` additionalProperties ` applies only to the property values for which neither
1711+ ` properties ` nor ` patternProperties ` apply.
17021712
17031713For all such properties, validation succeeds if the child instance validates
17041714against the ` additionalProperties ` schema.
17051715
1706- The annotation result of this keyword is the set of instance property names
1707- validated by this keyword's subschema. This annotation affects the behavior of
1708- ` unevaluatedProperties ` .
1709-
17101716Omitting this keyword has the same assertion behavior as an empty schema.
17111717
1712- Implementations MAY choose to implement or optimize this keyword in another way
1713- that produces the same effect, such as by directly checking the names in
1714- ` properties ` and the patterns in ` patternProperties ` against the instance
1715- property set. Implementations that do not support annotation collection MUST do
1716- so.[ ^ 12 ]
1717-
1718- [ ^ 12 ] : In defining this option, it seems there is the potential for ambiguity in
1719- the output format. The ambiguity does not affect validation results, but it does
1720- affect the resulting output format. The ambiguity allows for multiple valid
1721- output results depending on whether annotations are used or a solution that
1722- "produces the same effect" as draft-07. It is understood that annotations from
1723- failing schemas are dropped. See our [ Decision
1724- Record] ( https://github.com/json-schema-org/json-schema-spec/tree/HEAD/adr/2022-04-08-cref-for-ambiguity-and-fix-later-gh-spec-issue-1172.md )
1725- for further details.
1718+ The annotation result of this keyword is the set of instance property names
1719+ validated by this keyword's subschema.
1720+
1721+ The presence of this keyword affects the behavior of
1722+ [ ` unevaluatedProperties ` ] ( #unevaluatedproperties ) .
17261723
17271724##### ` propertyNames `
17281725
@@ -1757,17 +1754,18 @@ Validation MUST always succeed against this keyword. The value of this keyword
17571754is used as its annotation result.
17581755
17591756Per {{default-behaviors}}, omitted keywords MUST NOT produce annotation results.
1760- However, as described in the section for ` contains ` , the absence of this
1761- keyword's annotation causes ` contains ` to assume a minimum value of 1.
1757+ However, as described in {{ contains}} , the absence of this keyword's annotation
1758+ causes ` contains ` to assume a minimum value of 1.
17621759
1763- ##### ` contains `
1760+ ##### ` contains ` {#contains}
17641761
17651762The value of this keyword MUST be a valid JSON Schema.
17661763
1767- This keyword applies its subschema to array elements.
1764+ This keyword applies to array instances by applying its subschema to the array's
1765+ elements.
17681766
17691767An instance is valid against ` contains ` if the number of elements that are valid
1770- against its subschema is with the inclusive range of the minimum and (if any)
1768+ against its subschema is within the inclusive range of the minimum and (if any)
17711769maximum number of occurrences.
17721770
17731771The maximum number of occurrences is provided by the ` maxContains ` keyword
@@ -1778,24 +1776,26 @@ The minimum number of occurrences is provided by the `minContains` keyword
17781776within the same schema object as ` contains ` . If ` minContains ` is absent, the
17791777minimum number of occurrences MUST be 1.
17801778
1781- Implementations MAY implement the dependency on ` minContains ` and ` maxContains `
1782- by inspecting their values rather than reading annotations produced by those
1783- keywords.
1779+ This keyword produces an annotation value which is an array of the zero-based
1780+ indices for which this keyword validates successfully when applying its
1781+ subschema, in ascending order. The value MAY be a boolean ` true ` if the
1782+ subschema validates successfully when applied to every index of the instance.
1783+ The annotation MUST be present if the instance array to which this keyword's
1784+ schema applies is empty.
17841785
1785- This keyword produces an annotation value which is an array of the indexes to
1786- which this keyword validates successfully when applying its subschema, in
1787- ascending order. The value MAY be a boolean ` true ` if the subschema validates
1788- successfully when applied to every index of the instance. The annotation MUST be
1789- present if the instance array to which this keyword's schema applies
1790- is empty.
1786+ The presence of this keyword affects the behavior of
1787+ [ ` unevaluatedItems ` ] ( #unevaluateditems ) .
17911788
1792- This annotation affects the behavior of ` unevaluatedItems ` .
1789+ Under most circumstances, the ` contains ` subschema MAY be short-circuited.
1790+ However, for the following cases, the ` contains ` subschema MUST be applied to
1791+ every array element.
17931792
1794- The subschema MUST be applied to every array element even after the first match
1795- has been found, in order to collect annotations for use by other keywords. This
1796- is to ensure that all possible annotations are collected.
1793+ - If ` unevaluatedItems ` appears in any subschema in the dynamic scope that
1794+ applies to the same instance location, to ensure that all evaluated items are
1795+ accounted for.
1796+ - When collecting annotations, to ensure that all annotations are found.
17971797
1798- ## Keywords for Unevaluated Locations
1798+ ## Keywords for Unevaluated Locations {#unevaluated}
17991799
18001800The purpose of these keywords is to enable schema authors to apply subschemas to
18011801array items or object properties that have not been successfully evaluated
@@ -1811,16 +1811,16 @@ If an item in an array or an object property is "successfully evaluated", it is
18111811logically considered to be valid in terms of the representation of the object or
18121812array that's expected. For example if a subschema represents a car, which
18131813requires between 2-4 wheels, and the value of "wheels" is 6, the instance object
1814- is not "evaluated" to be a car, and the "wheels" property is considered
1815- "unevaluated (successfully as a known thing)", and does not retain any
1816- annotations.
1814+ is not "evaluated" to be a car, and thus the "wheels" property is considered
1815+ "unevaluated".
18171816
18181817Recall that adjacent keywords are keywords within the same schema object, and
18191818that the dynamic-scope subschemas include reference targets as well as lexical
18201819subschemas.
18211820
1822- The behavior of these keywords depend on the annotation results of adjacent
1823- keywords that apply to the instance location being validated.
1821+ The behaviors of these keywords depend on adjacent keywords as well as any
1822+ keywords in successfully validated subschemas that apply to the same instance
1823+ location.
18241824
18251825### Keyword Independence
18261826
@@ -1836,62 +1836,52 @@ outcomes. However, these keywords are notable exceptions:
18361836
18371837The value of ` unevaluatedItems ` MUST be a valid JSON Schema.
18381838
1839- The behavior of this keyword depends on the annotation results of adjacent
1840- keywords that apply to the instance location being validated. Specifically, the
1841- annotations from ` prefixItems ` , ` items ` , and ` contains ` , which can come from
1842- those keywords when they are adjacent to the ` unevaluatedItems ` keyword. Those
1843- three annotations, as well as ` unevaluatedItems ` , can also result from any and
1844- all adjacent [ in-place applicator] ( #in-place ) keywords. This includes but is not
1845- limited to the in-place applicators defined in this document.
1846-
1847- If no relevant annotations are present, the ` unevaluatedItems ` subschema MUST be
1848- applied to all locations in the array. If a boolean true value is present from
1849- any of the relevant annotations, ` unevaluatedItems ` MUST be ignored. Otherwise,
1850- the subschema MUST be applied to any index greater than the largest annotation
1851- value for ` prefixItems ` , which does not appear in any annotation value for
1852- ` contains ` .
1853-
1854- This means that ` prefixItems ` , ` items ` , ` contains ` , and all in-place applicators
1855- MUST be evaluated before this keyword can be evaluated. Authors of extension
1856- keywords MUST NOT define an in-place applicator that would need to be evaluated
1857- after this keyword.
1839+ This keyword applies to array instances by applying its subschema to the array's
1840+ elements.
1841+
1842+ The behavior of this keyword depends on all adjacent keywords as well as
1843+ keywords in successfully validated subschemas that apply to the same instance
1844+ location by evaluating the instance's elements. This includes, but is not
1845+ limited to, ` prefixItems ` , ` items ` , and ` contains ` , itself, and all
1846+ [ in-place applicators] ( #in-place ) defined in this document.
1847+
1848+ This keyword applies its subschema to any array elements which have not been
1849+ deemed "evaluated" per {{unevaluated}}. Validation passes if the keyword's
1850+ subschema validates against all applicable array elements.
18581851
18591852If the ` unevaluatedItems ` subschema is applied to any positions within the
18601853instance array, it produces an annotation result of boolean true, analogous to
1861- the behavior of ` items ` . This annotation affects the behavior of
1862- ` unevaluatedItems ` in parent schemas.
1854+ the behavior of ` items ` .
1855+
1856+ The presence of this keyword affects the behavior of other ` unevaluatedItems `
1857+ keywords found earlier in the dynamic scope that apply to the same instance
1858+ location.
18631859
18641860Omitting this keyword has the same assertion behavior as an empty schema.
18651861
18661862### ` unevaluatedProperties ` {#unevaluatedproperties}
18671863
18681864The value of ` unevaluatedProperties ` MUST be a valid JSON Schema.
18691865
1870- The behavior of this keyword depends on the annotation results of adjacent
1871- keywords that apply to the instance location being validated. Specifically, the
1872- annotations from ` properties ` , ` patternProperties ` , and ` additionalProperties ` ,
1873- which can come from those keywords when they are adjacent to the
1874- ` unevaluatedProperties ` keyword. Those four annotations, as well as
1875- ` unevaluatedProperties ` , can also result from any and all adjacent [ in-place
1876- applicator] ( #in-place ) keywords. This includes but is not limited to the
1877- in-place applicators defined in this document.
1866+ This keyword applies to object instances by applying its subschema to the object's
1867+ property values.
18781868
1879- Validation with ` unevaluatedProperties ` applies only to the child values of
1880- instance names that do not appear in the ` properties ` , ` patternProperties ` ,
1881- ` additionalProperties ` , or ` unevaluatedProperties ` annotation results that apply
1882- to the instance location being validated.
1869+ The behavior of this keyword depends on all adjacent keywords as well as
1870+ keywords in successfully validated subschemas that apply to the same instance
1871+ location by evaluating the instance's property values. This includes, but is not limited
1872+ to, ` properties ` , ` patternProperties ` , and ` additionalProperties ` , itself, and
1873+ all [ in-place applicators] ( #in-place ) defined in this document.
18831874
1884- For all such properties, validation succeeds if the child instance validates
1885- against the ` unevaluatedProperties ` schema.
1886-
1887- This means that ` properties ` , ` patternProperties ` , ` additionalProperties ` , and
1888- all in-place applicators MUST be evaluated before this keyword can be evaluated.
1889- Authors of extension keywords MUST NOT define an in-place applicator that would
1890- need to be evaluated after this keyword.
1875+ This keyword applies its subschema to any property values which have not been
1876+ deemed "evaluated" per {{unevaluated}}. Validation passes if the keyword's
1877+ subschema validates against all applicable property values.
18911878
18921879The annotation result of this keyword is the set of instance property names
1893- validated by this keyword's subschema. This annotation affects the behavior of
1894- ` unevaluatedProperties ` in parent schemas.
1880+ validated by this keyword's subschema.
1881+
1882+ The presence of this keyword affects the behavior of other ` unevaluatedProperties `
1883+ keywords found earlier in the dynamic scope that apply to the same instance
1884+ location.
18951885
18961886Omitting this keyword has the same assertion behavior as an empty schema.
18971887
0 commit comments