minProperties : Integer
minProperties
IntegerAn object instance is valid if its number of properties is greater than, or equal to, the value of this keyword.
Kind | Assertion |
---|---|
Applies To | Object |
Dialect | 2020-12 |
Introduced In | Draft 4 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.5.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Also see |
|
The minProperties
keyword is used to specify the inclusive minimum number of properties allowed in an object instnace. If the number of properties in the object is less than the value specified by minProperties
, the validation fails.
- It applies specifically to object instances.
- The value of this keyword must be a non-negative integer (0 or greater).
- Omitting this keyword has the same behavior as a value of 0.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minProperties": 1
}
{ "foo": 3, "bar": "hi" }
{}
false
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" },
"address": { "type": "string" }
},
"minProperties": 2
}
{ "name": "John", "age": 2 }
{ "name": "John" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"^[Aa]ge$": { "type": "integer" }
},
"additionalProperties": { "type": "string" },
"minProperties": 2
}
{ "Age": 22, "name": "John" }
{ "Age": 67 }
{ "myAge": "22", "name": "John" }
{ "myAge": 22, "name": "John" }