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 |
---|---|
Kind | Annotation |
Applies To | Any |
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 |
Affected By | None |
Affects | None |
Also See |
The examples
keyword is used to provide a list of example instances associated with a particular schema that should ideally validate against the schema. These examples serve to illustrate the intended structure and constraints defined by the schema. While these examples are not used for validation purposes, they are helpful in providing sample valid instances against the schema they are defined in.
Note: While it is recommended that the examples validate against the subschema they are defined in, this requirement is not strictly enforced.
- Used to demonstrate how data should conform to the schema.
examples
does not affect data validation but serves as an informative annotation.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"examples": [ "foo", "bar", "Doe" ],
"type": "string"
}
"John"
{ "keyword": "/examples", "instance": "", "value": [ "foo", "bar", "Doe" ] }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"properties": {
"foo": { "const": "foo" }
}
},
"then": {
"properties": {
"bar": {
"type": "array",
"examples": [ [ "foo" ], [ "bar", "baz" ] ]
}
}
},
"else": {
"properties": {
"bar": {
"type": "boolean",
"examples": [ false, true ]
}
}
}
}
{ "foo": "foo", "bar": [ "bar" ] }
{ "keyword": "/then/properties/bar/examples", "instance": "/bar", "value": [ [ "foo" ], [ "bar", "baz" ] ] }
{ "foo": "not foo", "bar": true }
{ "keyword": "/else/properties/bar/examples", "instance": "/bar", "value": [ false, true ] }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"examples": [ "John", "Karl" ],
"$ref": "#/$defs/name",
"$defs": {
"name": {
"examples": [ "John", "Karl" ],
"type": "string"
}
}
}
"John Doe"
{ "keyword": "/examples", "instance": "", "value": [ "John", "Karl" ] }
{ "keyword": "/$ref/examples", "instance": "", "value": [ "John", "Karl" ] }