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 preferably 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 | Draft 6 |
Changed In | None |
Introduced In | Draft 6 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.7.4 |
Metaschema | http://json-schema.org/draft-06/schema# |
Official Tests | None |
Default |
[]
|
Annotation | None |
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 is merely descriptive and does not affect
validation.
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": "http://json-schema.org/draft-06/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 }
{ "age": 50 }
{ "name": 1, "age": true }