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.

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 with 'minProperties' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "minProperties": 1
}
An instance with 1 or more properties is valid Instance
{ "foo": 3, "bar": "hi" }
An empty instance is invalid Instance
{}
'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
}
An instance with 2 or more properties is valid Instance
{ "name": "John", "age": 2 }
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
}
An instance with 2 or more properties is valid Instance
{ "Age": 22, "name": "John" }
An instance with less than 2 properties is invalid Instance
{ "Age": 67 }
An instance with additional properties conforming to the 'additionalProperties' schema is valid Instance
{ "myAge": "22", "name": "John" }
An instance with additional properties not conforming to the 'additionalProperties' schema is invalid Instance
{ "myAge": 22, "name": "John" }