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.

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

Valid instances:
Invalid instances:

At Least Two Properties

Valid instances:
Invalid instances:

maxProperties

Specifies the maximum number of properties an object can have.

Syntax

The value must be a non-negative integer.

Validation Rules

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

Examples

Limited Properties

Valid instances:
Invalid instances:

Single Property Object

Valid instances:
Invalid instances:

required

Specifies which properties must be present in an object.

Syntax

The value must be an array of strings. Elements must be unique.

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

Valid instances:
Invalid instances:

Single Required Field

Valid instances:
Invalid instances:

All Properties Required

Valid instance:
Invalid instances:

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.

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

Valid instances:
Invalid instances:

Multiple Dependencies

Valid instances:
Invalid instances:

Multiple Required Properties

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

This validates objects with 1 to 5 properties:
Invalid:

User Profile

Valid instance:

Configuration Object

Valid instances:
Invalid:

Address Validation

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

This validates objects with exactly 2 properties:

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)