minProperties : Integer
minProperties
IntegerAn object instance is valid if its number of properties is greater 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 |
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.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Official Tests | draft2020-12/minProperties.json |
Default |
0
|
Annotation | None |
Affected By | None |
Affects | None |
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.
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" }