Validate JSON data with schemas, types, required fields, formats, composition, and API contracts.
Lessons
Model alternatives and shared structure without duplicating schemas.
Composition with oneOf, anyOf and allOf is easiest to learn by reading the example, changing it, and observing the result.
{
"allOf": [{ "$ref": "#/$defs/timestamps" }],
"oneOf": [
{ "required": ["email"] },
{ "required": ["phone"] }
],
"$defs": {
"timestamps": {
"properties": { "createdAt": { "type": "string", "format": "date-time" } }
}
}
}Practice the Composition with oneOf, anyOf and allOf example in a small scratch file, then explain what changed and why.