Structured data explained
Disallow Extra JSON Properties After allOf: A Tested Draft 2020-12 Example
Compare additionalProperties in one allOf branch with unevaluatedProperties at the composed object. Test known, extra, missing and invalid fields.

At a glance
For fields composed with allOf in Draft 2020-12, keep the branches open and put unevaluatedProperties false on the outer object. A false additionalProperties inside just one branch can reject a field declared only in another branch. Run one valid and several invalid examples to check the difference.
In this guide
To disallow extras in a single JSON Schema object, put additionalProperties false beside the allowed properties. In an object assembled with allOf, work out which evaluations can see each property before closing it. This checked Draft 2020-12 example uses two branches.
Check the scope of the first closure rule
Branch A defines a string ticket and requires it. Branch B declares stage with two allowed values, open and closed, and requires it. The outside schema has type object and an allOf array containing A and B. When additionalProperties is false in branch A, its local property list does not contain stage. The instance with ticket T17 and stage open fails even though stage meets branch B.

Read the schema project’s extending-closed-schemas example Object reference: extending closed schemas.
Sources: Object reference: extending closed schemas · Draft 2020-12 Core, unevaluatedProperties
Move closure to the composed object
Remove the branch A closure and set unevaluatedProperties false at the same level as allOf. The first instance now passes. Both present properties were evaluated by successful branches. A debug field that neither branch covers still fails under the outer closure. Keep the same required arrays in both variants so you can see that the new closure does not make stage optional.


Choose the closure rule by object shape.
One declaration scope
Use additionalProperties false when the allowed names or patterns are all declared alongside it.
Two open allOf branches
Use unevaluatedProperties false on the outer schema in Draft 2020-12 if you want to close after those successful evaluations.
Check the Draft 2020-12 definition Draft 2020-12 Core, unevaluatedProperties.
Sources: Draft 2020-12 Core, unevaluatedProperties · Object reference: extending closed schemas
Run both valid and invalid cases
The local Ajv 8.20.0 fixture used the Draft 2020-12 validator with all errors reported and strictTypes disabled for the branch objects. The known pair passed only the outer schema. The extra debug property, missing stage and invalid value next failed in both variants for the reasons shown in the table. Use the same record for both schemas so a changed instance does not hide a change in scope. If a valid input fails, record the keyword and schema path so you can see which branch rejected it.
| Instance | Closed branch | Outer closure |
|---|---|---|
| ticket T17 and stage open | Fails: stage is extra in branch A | Passes |
| Both known fields plus debug true | Fails | Fails: debug is unevaluated |
| ticket present, stage missing | Fails: required | Fails: required |
| ticket T17, stage next | Fails | Fails: stage value |

Reproduce the matrix
- Select the Draft 2020-12 validator.
- Close only branch A and test both named properties.
- Open branch A and close the outer object instead.
- Check a valid pair, unknown property, missing field and invalid value.
Check which Ajv validator supports the dialect JSON Schema support in Ajv.
For the related task, see Test overlapping property rules.
Sources: Ajv · JSON Schema
Frequently asked questions
Does allOf merge properties into one declaration?
It evaluates the instance against each branch. Do not depend on sibling declarations becoming local to a closed branch.
Can I leave additionalProperties false inside the base and add outer closure?
The base can still fail independently. Move the closure out if the design calls for extension through that branch.
Does unevaluatedProperties require required as well?
Use required to assert that a field exists. Unevaluated closure restricts properties according to evaluation and answers a different question.
Can the same fixture be run as Draft 7?
This fixture’s outer closure uses Draft 2020-12. Choose the matching dialect before evaluating it. A Draft 7 schema can close a single scope with additionalProperties instead.
Read the additionalProperties scope
Check how a single declaration scope handles extra fields.
Read the additionalProperties scope guideContinue with a related guide
- Read the additionalProperties scope
Check how a single declaration scope handles extra fields.
- Test overlapping property rules
Read a separate example of names matched by two patterns.
- Test a version field with const
Keep type and value assertions separate.
References
- Object reference: extending closed schemas JSON Schema
- Draft 2020-12 Core, unevaluatedProperties JSON Schema
- JSON Schema support in Ajv Ajv