maxProperties : Integer

maxProperties

Integer

An object instance is valid if its number of properties is less than, or equal to, the value of this keyword.

Value This keyword must be set to a zero or positive integer
Kind Assertion
Applies To Object
Base Dialect 2020-12
Changed In None
Introduced In Draft 4
Vocabulary Validation
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.5.1
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/maxProperties.json
Default None
Annotation None
Affected By None
Affects None
Also See

The maxProperties keyword restricts object instances to consists of an inclusive maximum numbers of properties.

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 define at most 2 properties Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "maxProperties": 2
}
Invalid An object value with more than 2 properties is invalid Instance
{ "foo": 1, "bar": 2, "baz": 3 }
Valid An object value with 2 properties is valid Instance
{ "foo": 1, "bar": 2 }
Valid An object value with less than 2 properties is valid Instance
{ "foo": 1 }
Valid A non-object value is valid Instance
"Hello World"