minProperties : Integer

minProperties

Integer

An 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 with 'minProperties' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "minProperties": 1
}
Valid An instance with 1 or more properties is valid Instance
{ "foo": 3, "bar": "hi" }
Invalid An empty instance is invalid Instance
{}
Valid 'minProperties' has no effect on values other than objects Instance
false
Schema with 'minProperties' and 'properties' keywords Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" },
    "address": { "type": "string" }
  },
  "minProperties": 2
}
Valid An instance with 2 or more properties is valid Instance
{ "name": "John", "age": 2 }
Invalid An instance with less than 2 properties is invalid Instance
{ "name": "John" }
Schema with 'minProperties', 'patternProperties' and 'additionalProperties' keywords Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "patternProperties": {
    "^[Aa]ge$": { "type": "integer" }
  },
  "additionalProperties": { "type": "string" },
  "minProperties": 2
}
Valid An instance with 2 or more properties is valid Instance
{ "Age": 22, "name": "John" }
Invalid An instance with less than 2 properties is invalid Instance
{ "Age": 67 }
Valid An instance with additional properties conforming to the 'additionalProperties' schema is valid Instance
{ "myAge": "22", "name": "John" }
Invalid An instance with additional properties not conforming to the 'additionalProperties' schema is invalid Instance
{ "myAge": 22, "name": "John" }