TATECHATLAS
◎ English
Artificial intelligence / Tip

JSON Schema allOf extension: additionalProperties vs unevaluatedProperties

additionalProperties only sees properties in the same subschema, so allOf extension fails to reject unknown keys. Use unevaluatedProperties in draft 2019-09 or later to recognize nested subschema properties without redeclaring them.

On this page

additionalProperties only inspects properties declared in the same subschema. When a base schema defines properties and required fields inside an allOf array, an extending schema that adds new properties cannot rely on additionalProperties to reject unknown keys, because the keyword does not see those nested subschemas. The documented workaround is to move additionalProperties to the extending schema and redeclare the base properties, but that duplicates definitions and breaks when the base schema changes. The cleaner solution is unevaluatedProperties, introduced in draft 2019-09. It evaluates properties across all subschemas in allOf, so it recognizes properties declared in nested subschemas and correctly rejects unknown keys without redeclaring them. The trade-off is that unevaluatedProperties requires draft 2019-09 or later, and it does not declare allowed properties; you still need properties or patternProperties for that. It also cannot validate unknown keys against schemas that are not part of the combining operation.

Concrete illustration and applicability limits

The example schema combines two object subschemas with allOf. The first subschema declares street_address, city, and state as properties and requires them. The second subschema declares type as an enum of residential or business and requires it. An if/then rule adds department only when type is business. The extending schema sets unevaluatedProperties to false, which rejects any property not declared in the combined subschemas. The instance is valid because street_address, city, state, type, and department are all recognized. If the instance contained an unknown key, validation would fail because unevaluatedProperties is false. This works without redeclaring street_address, city, state, or type in the extending schema.

The key limitation is that unevaluatedProperties does not declare allowed properties. It only controls whether unknown keys are rejected after the combined subschemas have been evaluated. To allow specific keys, you still need properties or patternProperties. It also cannot validate unknown keys against schemas that are not part of the combining operation. If a property is declared in a schema that is not combined with allOf, unevaluatedProperties will not see it. The keyword is only available in draft 2019-09 or later. Older drafts require the redeclaration workaround, where additionalProperties is moved to the extending schema and base properties are duplicated.

The concrete illustration shows the difference between additionalProperties and unevaluatedProperties. With additionalProperties, a base schema that declares properties inside an allOf subschema cannot reject unknown keys in an extending schema, because the keyword only inspects properties declared in the same subschema. The documented workaround is to redeclare the base properties in the extending schema and set additionalProperties to false. That works but duplicates definitions and makes the schema fragile when the base schema changes. UnevaluatedProperties solves this by evaluating properties across all subschemas in allOf, so the extending schema can reject unknown keys without redeclaring the base properties.

Applicability limits include draft support, the need for properties or patternProperties to declare allowed keys, and the requirement that the schemas being combined are part of the same allOf operation. If the base schema is not combined through allOf, unevaluatedProperties may not recognize its properties. The keyword evaluates properties across the combined subschemas, so it depends on the combining operation being applied. It also does not replace properties or patternProperties for declaring allowed keys. The example uses a minimal address schema to show how allOf, if/then, and unevaluatedProperties interact, but the same pattern applies to any schema extension where nested subschemas declare properties.

schema: allOf: - type: object properties: street_address: type: string city: type: string state: type: string required: [street_address, city, state] - type: object properties: type: enum: [residential, business] required: [type] if: type: object properties: type: const: business then: properties: department: type: string unevaluatedProperties: false data: street_address: 1600 Pennsylvania Avenue NW city: Washington state: DC type: business department: HR

Why additionalProperties breaks schema extension with allOf

additionalProperties only inspects properties declared in the same subschema. When a base schema defines properties and required fields inside an allOf array, an extending schema that adds new properties cannot rely on additionalProperties to reject unknown keys, because the keyword does not see those nested subschemas. The documented example shows a base schema with allOf containing a subschema that declares street_address, city, and state, and a required array. An extending schema adds type and requires it, but additionalProperties still only recognizes street_address, city, and state. Any other property is treated as additional, so the extending schema cannot reject unknown keys without redeclaring the base properties.

The problem is that combining schemas with allOf does not change how additionalProperties works. Each subschema is evaluated independently for the purpose of additionalProperties, so properties declared in a later subschema are not visible to the keyword in the base or extending schema. This means that if you try to use additionalProperties to forbid unknown keys in an extended schema, it will either allow unwanted keys or require you to redeclare every property from the base schema. The workaround is to move additionalProperties to the extending schema and redeclare the properties from the extended schema, as shown in the source example. That makes additionalProperties able to recognize all the necessary properties, but it duplicates property definitions and breaks when the base schema changes.

The core issue is that additionalProperties is scoped to the properties keyword in the same schema object. It does not traverse allOf or anyOf or oneOf to find properties declared in nested subschemas. Therefore, when you extend a schema that uses allOf to declare object properties, additionalProperties cannot see those nested properties. The extending schema must either redeclare the base properties or use a keyword that evaluates across the combined subschemas. The source documentation explicitly states that combining the schemas with allOf does not change that behavior, and the workaround is to move additionalProperties to the extending schema and redeclare the properties from the extended schema.

This limitation matters for schema reuse. If you have a base schema that uses allOf to split object properties across multiple subschemas, you cannot simply add a new property and set additionalProperties to false in the extending schema. The keyword will not recognize the base properties, so it will reject them as unknown keys. You would need to redeclare every base property in the extending schema, which creates duplication and maintenance burden. The source documentation presents this as a known challenge when extending a schema using combining, and it leads to the introduction of unevaluatedProperties as the solution.

schema { " allOf " : [ { " type " : "object" , " properties " : { " street_address " : { " type " : "string" } , " city " : { " type " : "string" } , " state " : { " type " : "string" } } , " required " : [ "street_address" , "city" , "state" ] } ] , " properties " : { " street_address " : true , " city " : true , " state " : true , " type " : { " enum " : [ "residential" , "business" ] } } , " required " : [ "type" ] , " additionalProperties " : false }

How unevaluatedProperties recognizes nested subschema properties

unevaluatedProperties, introduced in draft 2019-09, is similar to additionalProperties except that it can recognize properties declared in subschemas. The source documentation shows that the previous example can be rewritten without redeclaring properties. The schema uses allOf to combine a subschema that declares street_address, city, and state with a subschema that declares type as an enum of residential or business. An if/then rule adds department only when type is business. The extending schema sets unevaluatedProperties to false, which rejects any property not declared in the combined subschemas. This works because unevaluatedProperties evaluates properties across all subschemas in allOf, so it recognizes properties declared in nested subschemas.

The mechanism is that unevaluatedProperties is evaluated after the combined subschemas have been applied. It checks the instance properties against the properties declared in all the subschemas that were evaluated, not just the properties declared in the same schema object. This means that properties declared in a subschema inside allOf are visible to unevaluatedProperties, even if they are not redeclared in the extending schema. The keyword can therefore reject unknown keys without requiring you to duplicate the base schema's properties. The source documentation explicitly states that the example can be rewritten without the need to redeclare properties, and that the properties declared in the then schema only count as evaluated properties if the type of the address is business.

The if/then rule in the example shows how unevaluatedProperties interacts with conditional schemas. The then schema declares department as a property, but that property is only evaluated when type is business. If type is residential, department is not evaluated, so it is not subject to the unevaluatedProperties check. This means that the unknown key rejection is conditional on the schema evaluation path. The source documentation shows that data with type residential and department HR is compliant, while data with type business and department HR is also compliant, but data with an unknown key is not compliant. This demonstrates that unevaluatedProperties recognizes properties from nested subschemas and applies the rejection based on the evaluated properties.

The key advantage over additionalProperties is that unevaluatedProperties does not require redeclaring the base properties. The extending schema only needs to declare new properties and set unevaluatedProperties to false. This avoids duplication and makes the schema easier to maintain. The source documentation presents this as the solution to the problem with additionalProperties when extending a schema using combining. The keyword is available only in draft 2019-09 and later, so older parsers will not support it. The example shows a minimal address schema with allOf, if/then, and unevaluatedProperties, but the same pattern applies to any schema extension where nested subschemas declare properties.

schema { " allOf " : [ { " type " : "object" , " properties " : { " street_addr
[excerpt]
 { " enum " : [ "residential" , "business" ] } } , " required " : [ "street_address" , "city" , "state" , "type" ] , " if " : { " type " : "object" , " properties " : { " type " : { " const " : "business" } } , " required " : [ "type" ] } , " then " : { " properties " : { " department " : { " type " : "string" } } } , " unevaluatedProperties " : false }

Practical recommendation and trade-offs

The practical recommendation is to use unevaluatedProperties for schema extension when you need to reject unknown keys and the base schema declares properties inside allOf. This avoids the redeclaration workaround that duplicates property definitions and makes the schema fragile when the base schema changes. The source documentation shows that the example from the additionalProperties section can be rewritten without redeclaring properties, and that the properties declared in the then schema only count as evaluated properties if the type of the address is business. The trade-off is that unevaluatedProperties requires draft 2019-09 or later, so you need a parser that supports that draft.

The redeclaration workaround works in older drafts but has clear downsides. You must move additionalProperties to the extending schema and redeclare the properties from the extended schema. This duplicates property definitions, which increases maintenance cost and the risk of inconsistency when the base schema changes. The source documentation presents this as a workaround, not a recommended pattern, and it explicitly introduces unevaluatedProperties as the solution. The trade-off is that unevaluatedProperties does not declare allowed properties; you still need properties or patternProperties for that. It also cannot validate unknown keys against schemas that are not part of the combining operation.

The comparison between the two approaches is important for schema design. additionalProperties is scoped to the properties keyword in the same schema object, so it cannot see properties declared in nested subschemas inside allOf. UnevaluatedProperties evaluates properties across all subschemas in allOf, so it recognizes properties declared in nested subschemas. The source documentation shows that the same schema can be written with additionalProperties and redeclared properties, or with unevaluatedProperties and no redeclaration. The latter is cleaner but requires a newer draft. The choice depends on the JSON Schema version your environment supports and whether you need to support older parsers.

Applicability limits include draft support, the need for properties or patternProperties to declare allowed keys, and the requirement that the schemas being combined are part of the same allOf operation. If the base schema is not combined through allOf, unevaluatedProperties may not see its properties. The keyword evaluates properties across the combined subschemas, so it depends on the combining operation being applied. It also does not replace properties or patternProperties for declaring allowed keys. The source documentation notes that additionalProperties is used to control the handling of extra properties, and that unevaluatedProperties is similar except that it can recognize properties declared in subschemas. The example shows a minimal address schema to illustrate the pattern, but the same principles apply to any schema extension where nested subschemas declare properties.

schema { " allOf " : [ { " type " : "object" , " properties " : { " street_addr
[excerpt]
 { " enum " : [ "residential" , "business" ] } } , " required " : [ "street_address" , "city" , "state" , "type" ] , " if " : { " type " : "object" , " properties " : { " type " : { " const " : "business" } } , " required " : [ "type" ] } , " then " : { " properties " : { " department " : { " type " : "string" } } } , " unevaluatedProperties " : false }

Applicability

  • Does the parser support draft 2019-09 or later?
  • Are the base properties declared inside an allOf array in the base schema?
  • Does the extending schema add new properties such as type and department?
  • Is the instance expected to be rejected when it contains an unknown key?
  • Does the schema use unevaluatedProperties instead of additionalProperties?
  • Are properties and required fields still declared in the nested subschemas?
  • Does the then branch only add department when type is business?
  • Is the instance valid when type is residential and department is absent?
  • Is the instance invalid when type is business but department is missing?
  • Does the schema reject unknown keys without redeclaring base properties?

unevaluatedProperties only works with draft 2019-09 or later. It does not declare allowed properties; use properties or patternProperties for that. It cannot validate unknown keys against schemas that are not part of the combining operation. It also does not replace the need for properties or patternProperties when you want to allow specific keys. If the base schema is not combined through allOf, unevaluatedProperties may not see its properties. The keyword evaluates properties across the combined subschemas, so it depends on the combining operation being applied.

Sources

  1. Python: json ↗
  2. JSON Schema: objects and required properties ↗
Back to top ↑