Validate JSON data with schemas, types, required fields, formats, composition, and API contracts.
Lessons
Apply rules based on a condition.
Conditionals: if, then, else is easiest to learn by reading the example, changing it, and observing the result.
{
"type": "object",
"properties": {
"type": { "enum": ["free", "paid"] },
"price": { "type": "number" }
},
"if": { "properties": { "type": { "const": "paid" } } },
"then": { "required": ["price"] },
"else": { "not": { "required": ["price"] } }
}Practice the Conditionals: if, then, else example in a small scratch file, then explain what changed and why.