Description
When defining mutually exclusive if-statements (if
, else-if
, else-if
, etc.), JSON Schema currently requires nesting with the else
statements. For shallow cases, this works fairly well. For example:
{
"if": { ... },
"then": { ... },
"else": {
"if": { ... },
"then": { ... },
"else": {
"if": { ... },
"then": { ... },
"else": { ... }
}
}
}
However, for highly complex use-case where there are hundreds of mutually exclusive conditions, this results in nested if-then-else
statements more than 100 deep. This complicates use-cases where clients are using JSON Schema for non-validation use-cases (e.g. mapping rules to their own data models from our JSON Schemas) as well as causes issues with commonly uses open-source validator implementations (~100 is a commonly used "safety" limit in some open source libraries to prevent infinite recursion).
Since conditional logic (if-then-else
) is defined by standard JSON Schema vocabularies, it would be ideal if we could come up with a way to flatten else-if
behaviors in the standard JSON Schema vocabularies (rather than using custom vocabularies that most open-source implementations would not be able to handle by default). Something like this:
{
"if": { ... },
"then": { ... },
"elseIf": [
{
"if": { ... },
"then": { ... }
},
{
"if": { ... },
"then": { ... }
}
],
"else": { ... }
}
Thanks for your consideration.