Skip to main content
JSON Schema provides several keywords for validating object instances.

minProperties

Specifies the minimum number of properties an object must have.

Syntax

The value must be a non-negative integer.
{
  "minProperties": 1
}

Validation Rules

An object instance is valid if its number of properties is greater than or equal to the specified value.

Default Behavior

Omitting minProperties is equivalent to minProperties: 0, which allows empty objects.

Examples

Non-Empty Object

{
  "type": "object",
  "minProperties": 1
}
Valid instances:
{"a": 1}
{"a": 1, "b": 2}
{"name": "John"}
Invalid instances:
{}

At Least Two Properties

{
  "type": "object",
  "minProperties": 2
}
Valid instances:
{"a": 1, "b": 2}
{"name": "John", "age": 30}
Invalid instances:
{}
{"a": 1}

maxProperties

Specifies the maximum number of properties an object can have.

Syntax

The value must be a non-negative integer.
{
  "maxProperties": 5
}

Validation Rules

An object instance is valid if its number of properties is less than or equal to the specified value.

Examples

Limited Properties

{
  "type": "object",
  "maxProperties": 3
}
Valid instances:
{}
{"a": 1}
{"a": 1, "b": 2, "c": 3}
Invalid instances:
{"a": 1, "b": 2, "c": 3, "d": 4}

Single Property Object

{
  "type": "object",
  "maxProperties": 1
}
Valid instances:
{}
{"status": "active"}
Invalid instances:
{"status": "active", "code": 200}

required

Specifies which properties must be present in an object.

Syntax

The value must be an array of strings. Elements must be unique.
{
  "required": ["name", "email"]
}

Validation Rules

An object instance is valid if every property name in the required array exists in the object.

Default Behavior

Omitting required is equivalent to an empty array, meaning no properties are required.

Examples

Required Fields

{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "email": {"type": "string"},
    "age": {"type": "integer"}
  },
  "required": ["name", "email"]
}
Valid instances:
{"name": "John", "email": "[email protected]"}
{"name": "Jane", "email": "[email protected]", "age": 30}
Invalid instances:
{"name": "John"}                    // Missing email
{"email": "[email protected]"}       // Missing name
{}                                   // Missing both

Single Required Field

{
  "type": "object",
  "properties": {
    "id": {"type": "integer"},
    "description": {"type": "string"}
  },
  "required": ["id"]
}
Valid instances:
{"id": 1}
{"id": 1, "description": "Item description"}
Invalid instances:
{"description": "Item description"}
{}

All Properties Required

{
  "type": "object",
  "properties": {
    "username": {"type": "string"},
    "password": {"type": "string"}
  },
  "required": ["username", "password"]
}
Valid instance:
{"username": "johndoe", "password": "secret123"}
Invalid instances:
{"username": "johndoe"}
{"password": "secret123"}
{}

dependentRequired

Specifies properties that are required if another specific property is present.

Syntax

The value must be an object. Each property’s value must be an array of strings (property names). Array elements must be unique.
{
  "dependentRequired": {
    "property1": ["property2", "property3"]
  }
}

Validation Rules

For each property name that appears both in the instance and as a key in dependentRequired, every property name in the corresponding array must also exist in the instance.

Default Behavior

Omitting dependentRequired is equivalent to an empty object, meaning no dependent requirements.

Examples

Credit Card Information

{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "credit_card": {"type": "string"},
    "billing_address": {"type": "string"}
  },
  "dependentRequired": {
    "credit_card": ["billing_address"]
  }
}
Valid instances:
{"name": "John"}                                           // No credit_card, no requirement
{"name": "John", "credit_card": "1234", "billing_address": "123 Main St"}  // Has both
Invalid instances:
{"name": "John", "credit_card": "1234"}  // Missing billing_address

Multiple Dependencies

{
  "type": "object",
  "properties": {
    "first_name": {"type": "string"},
    "last_name": {"type": "string"},
    "phone": {"type": "string"},
    "country_code": {"type": "string"}
  },
  "dependentRequired": {
    "phone": ["country_code"],
    "country_code": ["phone"]
  }
}
Valid instances:
{"first_name": "John", "last_name": "Doe"}
{"first_name": "John", "last_name": "Doe", "phone": "+1234567890", "country_code": "+1"}
Invalid instances:
{"first_name": "John", "phone": "+1234567890"}        // Missing country_code
{"first_name": "John", "country_code": "+1"}          // Missing phone

Multiple Required Properties

{
  "type": "object",
  "dependentRequired": {
    "shipping_method": ["shipping_address", "shipping_city", "shipping_zip"]
  }
}
If shipping_method is present, all three shipping address fields are required.

Combining Object Keywords

Multiple object validation keywords can be used together.

Property Count Range

{
  "type": "object",
  "minProperties": 1,
  "maxProperties": 5
}
This validates objects with 1 to 5 properties:
{"a": 1}
{"a": 1, "b": 2, "c": 3}
Invalid:
{}                                        // Too few
{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6}  // Too many

User Profile

{
  "type": "object",
  "properties": {
    "username": {"type": "string"},
    "email": {"type": "string"},
    "age": {"type": "integer"},
    "bio": {"type": "string"}
  },
  "required": ["username", "email"],
  "minProperties": 2,
  "maxProperties": 10
}
Valid instance:
{
  "username": "johndoe",
  "email": "[email protected]",
  "age": 30
}

Configuration Object

{
  "type": "object",
  "properties": {
    "host": {"type": "string"},
    "port": {"type": "integer"},
    "ssl": {"type": "boolean"},
    "ssl_cert": {"type": "string"},
    "ssl_key": {"type": "string"}
  },
  "required": ["host"],
  "dependentRequired": {
    "ssl": ["ssl_cert", "ssl_key"]
  }
}
Valid instances:
{"host": "example.com"}                                    // Minimal config
{"host": "example.com", "port": 443, "ssl": true, "ssl_cert": "cert.pem", "ssl_key": "key.pem"}
Invalid:
{}                                          // Missing required host
{"host": "example.com", "ssl": true}        // Missing ssl_cert and ssl_key

Address Validation

{
  "type": "object",
  "properties": {
    "street": {"type": "string"},
    "city": {"type": "string"},
    "state": {"type": "string"},
    "zip": {"type": "string"},
    "country": {"type": "string"}
  },
  "required": ["street", "city", "country"],
  "dependentRequired": {
    "state": ["zip"],
    "zip": ["state"]
  },
  "minProperties": 3
}
This ensures:
  • At least 3 properties total
  • Street, city, and country are always required
  • If state is provided, zip must be provided (and vice versa)

Exact Property Count

{
  "type": "object",
  "minProperties": 2,
  "maxProperties": 2
}
This validates objects with exactly 2 properties:
{"x": 10, "y": 20}
{"width": 100, "height": 200}

Use Cases

  • minProperties: Ensure objects are not empty or have minimum data
  • maxProperties: Limit object complexity or size
  • required: Enforce mandatory fields for data integrity
  • dependentRequired: Model conditional requirements (e.g., if shipping is selected, shipping address is required)

Build docs developers (and LLMs) love