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
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 with 'default' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "default": "John",
  "type": "number"
}
Valid An instance with a numeric value is valid Instance
45
Annotations
{ "keyword": "/default", "instance": "", "value": "John" }
Schema with logical operators Schema
{
  "$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" ]
  }
}
Valid An instance conforming to the schema is valid Instance
{
  "name": "Doe",
  "qualification": "degree",
  "degreeCertificate": "O5CYPZACTN"
}
Annotations
{ "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 with multiple annotations for the same instance Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "default": "John",
  "$ref": "#/$defs/name",
  "$defs": {
    "name": {
      "default": "John",
      "type": "string"
    }
  }
}
Valid A string instance is valid Instance
"Doe"
Annotations
{ "keyword": "/default", "instance": "", "value": "John" }
{ "keyword": "/$ref/default", "instance": "", "value": "John" }