{ "$id": "https://example.com/mySampleSchema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Complex Object", "type": "object", "$defs": { "colors": { "$anchor": "colorAnchor", "type": "string", "enum": [ "red", "green", "blue", "yellow" ] }, "car": { "type": "object", "properties": { "engineType": { "type": "string" }, "numWheels": { "type": "integer" } }, "required": ["engineType"] }, "bike": { "type": "object", "properties": { "bikeType": { "type": "string" }, "numWheels": { "type": "integer" } }, "required": ["bikeType"] } }, "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 18 }, "favouriteColor": { "$ref": "#colorAnchor" }, "address": { "type": "object", "properties": { "street": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" }, "postalCode": { "type": "string", "pattern": "\\d{5}" } }, "required": [ "street", "city", "state", "postalCode" ] }, "hobbies": { "type": "array", "items": { "type": "string" } }, "vehicleType": { "type": "string", "enum": ["car", "bike"] } }, "required": [ "name", "age" ], "if": { "properties": { "vehicleType": { "const": "car" } } }, "then": { "properties": { "vehicle": { "$ref": "#/$defs/car" } }, "required": ["vehicle"] }, "else": { "properties": { "vehicle": { "$ref": "#/$defs/bike" } }, "required": ["vehicle"] } }