default : Any
default
AnyThis keyword can be used to supply a default JSON value associated with a particular schema.
Value |
This keyword must be set to a JSON value, preferably that 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 4 |
Changed In | None |
Introduced In | Draft 1 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.6.2 |
Metaschema | http://json-schema.org/draft-04/schema# |
Official Tests | draft4/default.json |
Default | None |
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The default
keyword declares a
default instance value for a schema or any of its subschemas, typically to
support specialised tooling like documentation and form generators. This
keyword is merely descriptive and does not affect validation.
Common Pitfall
The standard evaluation process will not automatically use these values to fill in missing parts of the instance. Furthermore, the JSON Schema specification does not provide any guidance on how this keyword should be used.
Consult the documentation of any JSON Schema tooling you rely on to check if and how it makes use of this keyword.
Best Practice
Meta-schema validation will not check that the default values 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 default values 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-04/schema#",
"type": "object",
"default": {},
"properties": {
"language": { "default": "en" },
"notifications": { "default": true }
}
}
{ "language": "es", "notifications": false }
{}
"Hello World"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"email": {
"default": "johndoe@acme.com",
"$ref": "#/definitions/email-address"
}
},
"definitions": {
"email-address": {
"type": "string",
"format": "email",
"default": "example@example.org"
}
}
}
{ "email": "jane@foo.com" }
{}
{ "email": 1 }