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, 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.

Examples

A schema that declares top level and nested default values Schema
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "default": {},
  "properties": {
    "language": { "default": "en" },
    "notifications": { "default": true }
  }
}
Valid An object value that defines both properties is valid Instance
{ "language": "es", "notifications": false }
Valid An object value that omits both properties is valid Instance
{}
Invalid A non-object value is invalid Instance
"Hello World"
A schema that declares multiple default values for the same instance location Schema
{
  "$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"
    }
  }
}
Valid An object value that defines an email property is valid Instance
{ "email": "jane@foo.com" }
Valid An object value that omits the email property is valid Instance
{}
Invalid An object value with a non-string email property is invalid Instance
{ "email": 1 }