additionalProperties : Schema

additionalProperties

Schema

Validation succeeds if the schema validates against each value not matched by other object applicators in this vocabulary.

Value This keyword must be set to a valid JSON Schema
Kind Applicator Annotation
Applies To Object
Base Dialect 2020-12
Changed In None
Introduced In Draft 1
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.3.2.3
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/additionalProperties.json
Default {}
Annotation Array The set of instance property names validated by this keyword's subschema
Affected By
Affects
Also See

The additionalProperties keyword restricts object instance properties not described by the properties and patternProperties keywords (if any), to validate against the given subschema. Information about the properties that this keyword was evaluated for is reported using annotations.

Remember that JSON Schema is a constraint-driven language. Therefore, non-object instances successfully validate against this keyword. If needed, make use of the type keyword to constraint the accepted type accordingly.

Examples

A schema that constrains object instances to not define additional properties Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "foo": { "type": "string" }
  },
  "patternProperties": {
    "^x-": { "type": "integer" }
  },
  "additionalProperties": false
}
Valid An object value that defines properties that only match static and regular expression definitions is valid Instance
{ "foo": "bar", "x-test": 2 }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "foo" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "x-test" ] }
Invalid An object value that defines valid properties and also defines additional properties is invalid Instance
{ "foo": "bar", "x-test": 2, "extra": true }
Invalid An object value that only defines additional properties is invalid Instance
{ "extra": true, "random": 1234 }
Valid An empty object value is valid Instance
{}
Valid A non-object value is valid Instance
"Hello World"
A schema that constrains object instances to only define integer properties Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": { "type": "integer" }
}
Valid An object value that only defines integer properties is valid Instance
{ "foo": 1, "bar": 2, "baz": 3 }
Annotations
{ "keyword": "/additionalProperties", "instance": "", "value": [ "foo", "bar", "baz" ] }
Invalid An object value that defines at least one non-integer property is invalid Instance
{ "foo": 1, "name": "John Doe" }
Valid An empty object value is valid Instance
{}
Valid A non-object value is valid Instance
"Hello World"
A schema that constrains object instances to define boolean additional properties Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "foo": { "type": "string" }
  },
  "patternProperties": {
    "^x-": { "type": "integer" }
  },
  "additionalProperties": {
    "type": "boolean"
  }
}
Valid An object value that defines valid properties and boolean additional properties is valid Instance
{ "foo": "bar", "x-test": 2, "extra": true }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "foo" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "x-test" ] }
{ "keyword": "/additionalProperties", "instance": "", "value": [ "extra" ] }
Invalid An object value that defines valid properties and also defines non-boolean additional properties is invalid Instance
{ "foo": "bar", "x-test": 2, "extra": "should be a boolean" }
Valid An empty object value is valid Instance
{}
Valid A non-object value is valid Instance
"Hello World"