Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit ffd5185

Browse files
committed
Add documentation for contains keyword.
1 parent 0521a2f commit ffd5185

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

source/reference/array.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ array may be of a different type.
3434
single: array; items
3535
single: items
3636
single: additionalItems
37+
single: contains
3738

3839
Items
3940
'''''
4041

4142
By default, the elements of the array may be anything at all.
4243
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.
4546

4647
There are two ways in which arrays are generally used in JSON:
4748

@@ -91,6 +92,29 @@ number:
9192
// The empty array is always valid:
9293
[]
9394

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]
94118

95119
.. index::
96120
single: array; tuple validation

0 commit comments

Comments
 (0)