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

Commit 85633ed

Browse files
committed
Add examples
1 parent 0d181bb commit 85633ed

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

source/reference/generic.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,46 @@ for all JSON types.
88
single: metadata
99
single: title
1010
single: description
11+
single: examples
1112

1213
.. _metadata:
1314

1415
Metadata
1516
--------
1617

17-
JSON Schema includes a few keywords, ``title``, ``description`` and
18-
``default``, that aren't strictly used for validation, but are used to
19-
describe parts of a schema.
18+
JSON Schema includes a few keywords, ``title``, ``description``, ``default`` and
19+
``examples`` that aren't strictly used for validation, but are used to describe
20+
parts of a schema.
2021

2122
The ``title`` and ``description`` keywords must be strings. A "title"
2223
will preferably be short, whereas a "description" will provide a more
2324
lengthy explanation about the purpose of the data described by the
2425
schema. Neither are required, but they are encouraged for good
25-
practice.
26+
practice, and can make your schema "self-documenting".
2627

2728
The ``default`` keyword specifies a default value for an item. JSON
2829
processing tools may use this information to provide a default value
2930
for a missing key/value pair, though many JSON schema validators
3031
simply ignore the ``default`` keyword. It should validate against the
3132
schema in which it resides, but that isn't required.
3233

34+
|draft6| The ``examples`` keyword is a place to provide an array of examples
35+
that validate against the schema. This isn't used for validation, but may help
36+
with explaining the effect and purpose of the schema to a reader. Each entry
37+
should validate against the schema in which is resides, but that isn't strictly
38+
required. There is no need to duplicate the ``default`` value in the
39+
``examples`` array, since ``default`` will be treated as another example.
40+
3341
.. schema_example::
3442

3543
{
3644
"title" : "Match anything",
3745
"description" : "This is a schema that matches anything.",
38-
"default" : "Default value"
46+
"default" : "Default value",
47+
"examples" : [
48+
"Anything",
49+
4035
50+
]
3951
}
4052

4153
.. index::

0 commit comments

Comments
 (0)