examples : Array<Any>
examples
Array<Any>This keyword is used to provide sample JSON values associated with a particular schema, for the purpose of illustrating usage.
Value |
This keyword must be set to an array of JSON values that preferrably successfully validates against the corresponding subschema
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
---|---|
Kind | Annotation |
Applies To | Any |
Base Dialect | 2020-12 |
Changed In | None |
Introduced In | Draft 6 |
Vocabulary | Meta Data |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-9.5 |
Metaschema | https://json-schema.org/draft/2020-12/meta/meta-data |
Official Tests | draft2020-12/optional/refOfUnknownKeyword.json |
Default |
[]
|
Annotation |
Array
The set of examples set by this keyword
Hint: Use the jsonschema validate command to collect annotations from the command-line
|
Affected By | None |
Affects | None |
Also See |
The examples
keyword declares a set of example instances for a schema or any
of its subschemas, typically for documentation purposes. This keyword does not
affect validation, but the evaluator will collect its set of values as an
annotation.
Best Practice
Meta-schema validation will not check that the examples you declare are actually valid against their respective schemas, as JSON Schema does not offer a mechanism for meta-schemas to declare that instances validate against parts of the same instance being evaluated. As a consequence, it is not rare for schemas to declare invalid examples that go undetected for a long time.
It is recommended to use the jsonschema lint
command, as this linter performs further checks to detect many corner cases,
including this one.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"examples": [
{ "name": "John Doe", "age": 23 }
],
"properties": {
"name": {
"type": "string",
"examples": [ "John Doe", "Jane Doe" ]
},
"age": {
"type": "integer",
"examples": [ 1, 18, 55 ]
}
}
}
{ "name": "Juan Cruz Viotti", "age": 30 }
{ "keyword": "/examples", "instance": "", "value": [ { "name": "John Doe", "age": 23 } ] }
{ "keyword": "/properties/name/examples", "instance": "/name", "value": [ "John Doe", "Jane Doe" ] }
{ "keyword": "/properties/age/examples", "instance": "/age", "value": [ 1, 18, 55 ] }
{ "age": 50 }
{ "keyword": "/examples", "instance": "", "value": [ { "name": "John Doe", "age": 23 } ] }
{ "keyword": "/properties/age/examples", "instance": "/age", "value": [ 1, 18, 55 ] }
{ "name": 1, "age": true }