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
OmittingminProperties is equivalent to minProperties: 0, which allows empty objects.
Examples
Non-Empty Object
At Least Two Properties
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
Single Property Object
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 therequired array exists in the object.
Default Behavior
Omittingrequired is equivalent to an empty array, meaning no properties are required.
Examples
Required Fields
Single Required Field
All Properties Required
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 independentRequired, every property name in the corresponding array must also exist in the instance.
Default Behavior
OmittingdependentRequired is equivalent to an empty object, meaning no dependent requirements.
Examples
Credit Card Information
Multiple Dependencies
Multiple Required Properties
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
User Profile
Configuration Object
Address Validation
- 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
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)