You can express this using oneOf
. This means that the data must match exactly one of the supplied sub-schemas, but not more than one.
Combining this with required
, this schema says that instances must either define start_dt
, OR define end_dt
- but if they contain both, then it is invalid:
{
"type": "object",
"properties": {
"name": {"type": "string"},
"start_dt": {"type": "string", "format": "date"},
"end_dt": {"type": "string", "format": "date"}
},
"oneOf": [
{"required": ["start_dt"]},
{"required": ["end_dt"]}
]
}
Online demos with your three examples: