Validate JSON data with schemas, types, required fields, formats, composition, and API contracts.
Lessons
Provide clear, custom messages for failures.
Custom Error Messages is easiest to learn by reading the example, changing it, and observing the result.
// Ajv error objects map cleanly to API/UI messages
const errors = validate.errors.map(e => ({
field: e.instancePath.replace(/^\//, '') || e.params.missingProperty || '(root)',
message: e.message
}));
console.log(errors);
// [ { field: 'title', message: 'must NOT have fewer than 3 characters' } ]Practice the Custom Error Messages example in a small scratch file, then explain what changed and why.