Control additional properties in JSON Schema
How additionalProperties works in JSON Schema: open, closed and typed objects, the allOf pitfall, unevaluatedProperties, and when to keep a schema open.
The additionalProperties keyword decides what a JSON Schema does with object members it was not told about. It is one of the most useful keywords for catching typos and unexpected payloads, and one of the most common sources of confusing validation failures. This review explains what the keyword checks, what it leaves alone, where it behaves differently from what people expect, and when a closed schema is the right choice.
What additionalProperties checks
When the instance being validated is an object, additionalProperties applies to every member whose name is not listed in the sibling properties keyword and does not match any regular expression in the sibling patternProperties keyword. Those leftover members are validated against the value of additionalProperties. If the keyword is absent, leftover members are allowed with no constraints, which is the same as setting it to true.
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"additionalProperties": false
}
Against this schema, the instance {"name": "Ada", "age": 36} is valid because both members are declared. The instance {"name": "Ada", "nickname": "A"} is invalid because nickname is not declared and false rejects any leftover member. Note that {} is also valid: additionalProperties says nothing about which members must be present.
The three common settings
| Setting | Effect on undeclared members | Typical use |
| Omitted or true | Allowed, any value | Extensible payloads, partial validation, forward compatibility |
| false | Rejected | Configuration files, strict API requests, catching misspelled keys |
| A schema, such as {"type": "string"} | Allowed only if each value matches that schema | Dictionaries or maps with arbitrary keys and uniform values |
{
"type": "object",
"properties": { "id": { "type": "string" } },
"patternProperties": { "^x-": {} },
"additionalProperties": { "type": "number" }
}
In this example, id is checked by properties, any member starting with x- is accepted by patternProperties, and everything else must be a number. So {"id": "a", "x-note": "hi", "count": 3} is valid, while {"id": "a", "label": "b"} fails because label is neither declared nor numeric. If you want to constrain the names of extra members rather than their values, the propertyNames keyword is the tool for that.
What it does not change
In the specification, additionalProperties is a validation keyword. It reports whether an instance passes; it does not edit the data. Extra members are not removed, renamed or reordered by the schema itself. Some validator libraries offer options that strip unrecognized members during validation, but that is implementation-specific behavior layered on top of the standard, so check your library's documentation before relying on it. The keyword also does not make anything required, that is the job of required, and it has no effect when the instance is not an object, so a string or array passes this particular check. Add "type": "object" if non-objects should be rejected.
The composition pitfall
additionalProperties only looks at properties and patternProperties in the same schema object. It cannot see members declared inside allOf, anyOf, oneOf, $ref targets or conditional branches. Closing a schema that is built by composition therefore tends to reject members you intended to allow.
{
"allOf": [
{ "properties": { "id": { "type": "string" } } }
],
"properties": { "name": { "type": "string" } },
"additionalProperties": false
}
Here {"id": "x1", "name": "Ada"} fails. The allOf branch accepts id, but additionalProperties only knows about name, so it treats id as extra and rejects it. The usual workarounds before newer drafts were to repeat every property name at the top level or to avoid closing composed schemas at all.
Draft 2019-09 introduced unevaluatedProperties to solve this. It rejects or constrains members that no subschema evaluated, including members accepted by successful allOf branches and by referenced schemas. Replacing additionalProperties: false with unevaluatedProperties: false in the example above makes the instance valid, while a member such as role would still be rejected.
{
"allOf": [
{ "properties": { "id": { "type": "string" } } }
],
"properties": { "name": { "type": "string" } },
"unevaluatedProperties": false
}
Will it behave the same in every tool?
additionalProperties has been part of JSON Schema since early drafts and is broadly supported, but surrounding behavior varies. unevaluatedProperties only exists in validators that implement draft 2019-09 or later; older validators may ignore it as an unknown keyword, which silently leaves the schema open. Declare the dialect with the $schema keyword and confirm your validator supports it. In API descriptions, OpenAPI 3.1 aligns with JSON Schema 2020-12, while OpenAPI 3.0 uses its own subset, so the newer keyword may not be available there. Error message wording and whether a validator reports every failing member or stops at the first also differ between implementations. No validator was tested for this article, so treat these as points to verify against your own toolchain rather than observed results.
Should you close your schema?
The main benefit of additionalProperties: false is that mistakes surface early: a misspelled key in a configuration file or an unexpected field in a request fails validation instead of being silently ignored. The decisive tradeoff is forward compatibility. A closed schema rejects any member added later by a newer client, producer or plugin, so every extension requires a schema change on the consuming side.
- Close the schema when you own both the data and the schema, such as configuration files, internal service contracts or user input you want to reject strictly.
- Use a schema value instead of false when the object is really a map with arbitrary keys and uniform values.
- Prefer unevaluatedProperties over additionalProperties when the object is assembled from allOf, $ref or conditional subschemas, provided your validator supports draft 2019-09 or later.
- Leave the schema open when data comes from parties who may add fields independently, when you only validate the parts you consume, or when old readers must tolerate newer documents.
Gaps in this review
No implementation-specific evidence was supplied, so this review covers behavior defined by the JSON Schema specification and does not report measured results, performance figures or comparisons between named validators. Options for stripping extra members, error formats and draft support should be confirmed in the documentation of the validator you use and with a small test against representative data.