Skip to content

✨ Proposal: Add a Global defaultAdditionalProperties Toggle at the Root Level #1587

Open
@dani2819

Description

@dani2819

Describe the inspiration for your proposal

Currently, JSON Schema requires additionalProperties: false to be set explicitly on every object where I want to disallow extra properties. This gets repetitive when I want all objects in my schema (root and nested) to enforce this rule consistently. For example, I have a schema like this:

{
  'type': 'object',
  'additionalProperties': false,
  'properties': {
    'name': { 'type': 'string' },
    'details': {
      'type': 'object',
      'additionalProperties': false,
      'properties': {
        'age': { 'type': 'integer' },
        'city': { 'type': 'string' }
      }
    }
  }
}

I have to repeat additionalProperties: false for both the root object and the details object. In a larger schema with many nested objects, this repetition grows tedious and increases the chance of forgetting it somewhere. There’s no way to set this once globally and have it cascade to all objects, so I’m stuck either duplicating it or using $ref to a shared definition, which still requires manual application each time. A global setting would make this cleaner and align with the DRY.

Describe the proposal

Add a new root-level keyword, like defaultAdditionalProperties, that sets the default value for additionalProperties across all objects in the schema unless overridden. For example:

{
  '$schema': 'http://json-schema.org/draft-07/schema#',
  'defaultAdditionalProperties': false,
  'type': 'object',
  'properties': {
    'name': { 'type': 'string' },
    'details': {
      'type': 'object',
      'properties': {
        'age': { 'type': 'integer' }
      }
    }
  }
}

Benefits

  • Reduces redundancy and simplifies schemas.
  • Makes strict schemas easier to write and maintain.
  • Still allows flexibility with local overrides.
  • Aligns with other global defaults in JSON Schema (e.g., default for values).

Describe alternatives you've considered

  • Using $defs and $ref works but still requires explicit references per object, not a true global solution.
  • Preprocessing schemas externally is an option, but it’s outside the spec and not portable.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalInitial discussion of a new idea. A project will be created once a proposal document is created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions