additionalProperties : Schema | Boolean

additionalProperties

Schema | Boolean

Validation succeeds if the schema validates against each value not matched by other object applicators in this vocabulary. If set to false, no additional properties are allowed in the instance.

Value This keyword must be set to a valid JSON Schema Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
Kind Applicator
Applies To Object
Base Dialect Draft 4
Changed In None
Introduced In Draft 0
Vocabulary Validation
Specification https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.5.4.4
Metaschema http://json-schema.org/draft-04/schema#
Official Tests draft4/additionalProperties.json
Default {}
Annotation None
Affected By
Affects None
Also See

The additionalProperties keyword restricts object instance properties not described by the sibling properties and patternProperties keywords (if any), to validate against the given subschema.

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": "http://json-schema.org/draft-04/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 }
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": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": { "type": "integer" }
}
Valid An object value that only defines integer properties is valid Instance
{ "foo": 1, "bar": 2, "baz": 3 }
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": "http://json-schema.org/draft-04/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 }
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"

The additionalProperties keyword restricts object instance properties not described by the sibling properties and patternProperties keywords (if any), to validate against the given subschema.

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": "http://json-schema.org/draft-04/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 }
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": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": { "type": "integer" }
}
Valid An object value that only defines integer properties is valid Instance
{ "foo": 1, "bar": 2, "baz": 3 }
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": "http://json-schema.org/draft-04/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 }
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"