@@ -1613,6 +1613,12 @@ results.
1613
1613
1614
1614
#### Keywords for Applying Subschemas to Arrays
1615
1615
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
+
1616
1622
##### ` prefixItems `
1617
1623
1618
1624
The 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.
1625
1631
This keyword produces an annotation value which is the largest index to which
1626
1632
this keyword applied a subschema. The value MAY be a boolean true if a subschema
1627
1633
was 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 ) .
1629
1638
1630
1639
##### ` items ` {#items}
1631
1640
1632
1641
The value of ` items ` MUST be a valid JSON Schema.
1633
1642
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.
1639
1647
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.
1644
1653
1645
1654
If the ` items ` subschema is applied to any positions within the instance array,
1646
1655
it 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.
1649
1657
1650
1658
Omitting this keyword has the same assertion behavior as an empty schema.
1651
1659
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 ) .
1656
1662
1657
1663
#### Keywords for Applying Subschemas to Objects
1658
1664
@@ -1665,11 +1671,13 @@ Validation succeeds if, for each name that appears in both the instance and as a
1665
1671
name within this keyword's value, the child instance for that name successfully
1666
1672
validates against the corresponding schema.
1667
1673
1674
+ Omitting this keyword has the same assertion behavior as an empty object.
1675
+
1668
1676
The 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.
1671
1678
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 ) .
1673
1681
1674
1682
##### ` patternProperties `
1675
1683
@@ -1684,45 +1692,34 @@ instance for that name successfully validates against each schema that
1684
1692
corresponds to a matching regular expression. Recall: regular expressions are
1685
1693
not implicitly anchored.
1686
1694
1695
+ Omitting this keyword has the same assertion behavior as an empty object.
1696
+
1687
1697
The 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.
1690
1699
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 ) .
1692
1703
1693
1704
##### ` additionalProperties ` {#additionalproperties}
1694
1705
1695
1706
The value of ` additionalProperties ` MUST be a valid JSON Schema.
1696
1707
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.
1702
1712
1703
1713
For all such properties, validation succeeds if the child instance validates
1704
1714
against the ` additionalProperties ` schema.
1705
1715
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
-
1710
1716
Omitting this keyword has the same assertion behavior as an empty schema.
1711
1717
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 ) .
1726
1723
1727
1724
##### ` propertyNames `
1728
1725
@@ -1757,17 +1754,18 @@ Validation MUST always succeed against this keyword. The value of this keyword
1757
1754
is used as its annotation result.
1758
1755
1759
1756
Per {{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.
1762
1759
1763
- ##### ` contains `
1760
+ ##### ` contains ` {#contains}
1764
1761
1765
1762
The value of this keyword MUST be a valid JSON Schema.
1766
1763
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.
1768
1766
1769
1767
An 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)
1771
1769
maximum number of occurrences.
1772
1770
1773
1771
The 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
1778
1776
within the same schema object as ` contains ` . If ` minContains ` is absent, the
1779
1777
minimum number of occurrences MUST be 1.
1780
1778
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.
1784
1785
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 ) .
1791
1788
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.
1793
1792
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.
1797
1797
1798
- ## Keywords for Unevaluated Locations
1798
+ ## Keywords for Unevaluated Locations {#unevaluated}
1799
1799
1800
1800
The purpose of these keywords is to enable schema authors to apply subschemas to
1801
1801
array 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
1811
1811
logically considered to be valid in terms of the representation of the object or
1812
1812
array that's expected. For example if a subschema represents a car, which
1813
1813
requires 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".
1817
1816
1818
1817
Recall that adjacent keywords are keywords within the same schema object, and
1819
1818
that the dynamic-scope subschemas include reference targets as well as lexical
1820
1819
subschemas.
1821
1820
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.
1824
1824
1825
1825
### Keyword Independence
1826
1826
@@ -1836,62 +1836,52 @@ outcomes. However, these keywords are notable exceptions:
1836
1836
1837
1837
The value of ` unevaluatedItems ` MUST be a valid JSON Schema.
1838
1838
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.
1858
1851
1859
1852
If the ` unevaluatedItems ` subschema is applied to any positions within the
1860
1853
instance 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.
1863
1859
1864
1860
Omitting this keyword has the same assertion behavior as an empty schema.
1865
1861
1866
1862
### ` unevaluatedProperties ` {#unevaluatedproperties}
1867
1863
1868
1864
The value of ` unevaluatedProperties ` MUST be a valid JSON Schema.
1869
1865
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.
1878
1868
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.
1883
1874
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.
1891
1878
1892
1879
The 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.
1895
1885
1896
1886
Omitting this keyword has the same assertion behavior as an empty schema.
1897
1887
0 commit comments