wiki.busyhe.com
navigation

Applying subschemas conditionally (1)

if, then and else keywords
{ "type": "object", "properties": { "street_address": { "type": "string" }, "country": { "enum": ["United States of America", "Canada"] } }, "if": { "properties": { "country": { "const": "United States of America" } } }, "then": { "properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } } }, "else": { "properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } } } }

{ "street_address": "1600 Pennsylvania Avenue NW", "country": "United States of America", "postal_code": "20500" }
{ "street_address": "24 Sussex Drive", "country": "Canada", "postal_code": "K1M 1M4" }
{ "street_address": "24 Sussex Drive", "country": "Canada", "postal_code": "10000" }
badge