Validate JSON data with schemas, types, required fields, formats, composition, and API contracts.
Lessons
Model variant objects with a type field and oneOf.
Tagged Unions is easiest to learn by reading the example, changing it, and observing the result.
{
"oneOf": [
{
"properties": { "type": { "const": "card" }, "last4": { "type": "string" } },
"required": ["type", "last4"]
},
{
"properties": { "type": { "const": "paypal" }, "email": { "type": "string" } },
"required": ["type", "email"]
}
]
}Practice the Tagged Unions example in a small scratch file, then explain what changed and why.