properties keyword defines schemas that validate specific properties of a JSON object. Each property name maps to a schema that validates the corresponding property value.
Syntax
Behavior
Validation succeeds if, for each property name that appears in both the instance and this keyword’s value, the instance property value validates against the corresponding schema.- Only properties present in both the instance and
propertiesare validated - Additional properties in the instance are ignored by this keyword
- Missing properties specified in
propertiesare allowed (userequiredto mandate them) - Produces an annotation containing the set of property names validated
- Affects behavior of
additionalPropertiesandunevaluatedProperties
Examples
Basic Object Schema
Define expected object properties:Nested Objects
Define schemas for nested object properties:With Required Properties
Combine withrequired to mandate specific properties:
Complex Property Schemas
Use advanced schemas for property validation:API Response Schema
Define structure for API responses:Configuration Object
Validate application configuration:Using References
Reuse property schemas with$ref:
Interaction with Other Keywords
With additionalProperties
properties determines which properties are considered “known”:
{ "name": "Alice" }Invalid:
{ "name": "Alice", "age": 30 } (age is additional)
With patternProperties
Both can apply to the same property:name property must satisfy both schemas.
With unevaluatedProperties
Properties validated byproperties are marked as evaluated:
{ "id": 1 }Invalid:
{ "id": 1, "name": "test" }
Annotations
Theproperties keyword produces an annotation containing the set of instance property names that were validated. This annotation is used by:
additionalPropertiesto determine which properties are “additional”unevaluatedPropertiesto determine which properties are “unevaluated”
Common Use Cases
- Object validation: Define structure and constraints for JSON objects
- API schemas: Validate request/response payloads
- Configuration files: Ensure config objects have correct structure
- Data models: Define entity schemas for data validation
- Form validation: Validate user input objects
Notes
- Omitting
propertiesis equivalent to an empty object (no validation) - Properties not listed in
propertiesare not validated by this keyword - Use
requiredseparately to mandate property presence - Combines naturally with
additionalPropertiesto control object shape - The annotation is essential for the proper functioning of
additionalPropertiesandunevaluatedProperties
Best Practices
- Always specify
type: "object"when usingproperties - Use
requiredto explicitly list mandatory properties - Combine with
additionalProperties: falsefor strict object shapes - Use
$refto reuse common property schemas - Provide clear descriptions for each property to aid documentation