This repository was archived by the owner on Nov 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,15 @@ array may be of a different type.
34
34
single: array; items
35
35
single: items
36
36
single: additionalItems
37
+ single: contains
37
38
38
39
Items
39
40
'''''
40
41
41
42
By default, the elements of the array may be anything at all.
42
43
However, it's often useful to validate the items of the array against
43
- some schema as well. This is done using the ``items `` and
44
- ``additionalItems `` keywords.
44
+ some schema as well. This is done using the ``items ``,
45
+ ``additionalItems `` and `` contents `` keywords.
45
46
46
47
There are two ways in which arrays are generally used in JSON:
47
48
@@ -91,6 +92,29 @@ number:
91
92
// The empty array is always valid:
92
93
[]
93
94
95
+ |draft6 |
96
+
97
+ While the ``items `` schema must be valid for **every ** item in the array, the
98
+ ``contains `` schema only needs to validate against one or more items in the
99
+ array.
100
+
101
+ .. schema_example ::
102
+
103
+ {
104
+ "type": "array",
105
+ "contains": {
106
+ "type": "number"
107
+ }
108
+ }
109
+ --
110
+ // A single "number" is enough to make this pass:
111
+ ["life", "universe", "everything", 42]
112
+ --X
113
+ // But if we have no number, it fails:
114
+ ["life", "universe", "everything", "forty-two"]
115
+ --
116
+ // All numbers is, of course, also okay:
117
+ [1, 2, 3, 4, 5]
94
118
95
119
.. index ::
96
120
single: array; tuple validation
You can’t perform that action at this time.
0 commit comments