default : Any

default

Any

This 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 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 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 Hint: Use the jsonschema validate command to collect annotations from the command-line
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 does not affect validation, but the evaluator will collect its value as an annotation.

Examples

A schema that declares top level and nested default values Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "default": {},
  "properties": {
    "language": { "default": "en" },
    "notifications": { "default": true }
  }
}
Valid An object value that defines both properties is valid and annotations are emitted Instance
{ "language": "es", "notifications": false }
Annotations
{ "keyword": "/default", "instance": "", "value": {} }
{ "keyword": "/properties/language/default", "instance": "/language", "value": "en" }
{ "keyword": "/properties/notifications/default", "instance": "/notifications", "value": true }
Valid An object value that omits both properties is valid but their default values are (perhaps counter-intuitively) not emitted Instance
{}
Annotations
{ "keyword": "/default", "instance": "", "value": {} }
Invalid A non-object value is invalid and no annotations are emitted Instance
"Hello World"
A schema that declares multiple default values for the same instance location Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "email": {
      "default": "johndoe@acme.com",
      "$ref": "#/$defs/email-address"
    }
  },
  "$defs": {
    "email-address": {
      "type": "string",
      "format": "email",
      "default": "example@example.org"
    }
  }
}
Valid An object value that defines an email property is valid and both annotations are emitted Instance
{ "email": "jane@foo.com" }
Annotations
{ "keyword": "/properties/email/default", "instance": "/email", "value": "johndoe@acme.com" }
{ "keyword": "/$defs/email-address/default", "instance": "/email", "value": "example@example.org" }
Valid An object value that omits the email property is valid but the default values are (perhaps counter-intuitively) not emitted Instance
{}
Invalid An object value with a non-string email property is invalid and no annotations are emitted Instance
{ "email": 1 }