Validate nested object and array properties (Deep Rules)
masterTo validate deep structures, use the fields property within an object or array type rule.
- For Objects: Assign a
fieldsobject containing rules for the nested properties. - For Arrays: Assign a
fieldsobject where keys are indices (e.g.,'0','1') to validate specific elements. defaultField: Forarrayorobjecttypes, you can usedefaultFieldto apply the same rule to all elements/values in the container. This is expanded tofieldsinternally.
const descriptor = {
address: {
type: 'object',
required: true,
fields: {
street: { type: 'string', required: true },
city: { type: 'string', required: true },
},
},
urls: {
type: 'array',
required: true,
defaultField: { type: 'url' },
},
};