maxProperties : Integer
maxProperties
IntegerAn 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.
Common Pitfall
The presence of this keyword does not depend on the presence of the
properties
keyword.
Best Practice
To restrict object instances to the empty object, prefer using the
const
keyword instead of
setting this keyword to 0
.
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
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxProperties": 2
}
{ "foo": 1, "bar": 2, "baz": 3 }
{ "foo": 1, "bar": 2 }
{ "foo": 1 }
"Hello World"