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, preferrably that successfully validates against the corresponding subschema |
---|---|
Kind | Annotation |
Applies To | Any |
Dialect | 2020-12 |
Changed In | None |
Introduced In | Draft 1 |
Vocabulary | Meta Data |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-9.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/meta-data |
Official Tests | draft2020-12/default.json |
Default | None |
Annotation | Any The default value set by this keyword |
Affected By | None |
Affects | None |
Also See |
The default
keyword in JSON Schema is used to specify a default value for an instance. This value is not automatically used to fill in missing values during the validation process but can be used by tools such as documentation or form generators.
Note: While it is recommended that the default value validate against its subschema, this requirement is not strictly enforced.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"default": "John",
"type": "number"
}
45
{ "keyword": "/default", "instance": "", "value": "John" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"name": { "type": "string", "default": "John" },
"qualification": {
"enum": [ "degree", "diploma" ],
"default": "diploma"
}
},
"if": {
"properties": {
"qualification": { "const": "degree" }
}
},
"then": {
"properties": {
"degreeCertificate": {
"type": "string",
"default": "B0B8RKEZ90"
}
},
"required": [ "degreeCertificate" ]
},
"else": {
"properties": {
"diplomaCertificate": {
"type": "string",
"default": "PW458C468E"
}
},
"required": [ "diplomaCertificate" ]
}
}
{
"name": "Doe",
"qualification": "degree",
"degreeCertificate": "O5CYPZACTN"
}
{ "keyword": "/properties/name/default", "instance": "/name", "value": "John" }
{ "keyword": "/properties/qualification/default", "instance": "/qualification", "value": "diploma" }
{ "keyword": "/then/properties/degreeCertificate/default", "instance": "/degreeCertificate", "value": "B0B8RKEZ90" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"default": "John",
"$ref": "#/$defs/name",
"$defs": {
"name": {
"default": "John",
"type": "string"
}
}
}
"Doe"
{ "keyword": "/default", "instance": "", "value": "John" }
{ "keyword": "/$ref/default", "instance": "", "value": "John" }