I want to validate a JSON file using JSON schema, several "properties" should be required depending on what values some other properties have.
Example
- Having properties "A", "B", "C", and "D"
- if "A" has value "foo", C is required
- if "B" has value "foo", D is required
- if both "A" and "B" each have value "foo", both C and D are required
- else, nothing is required
I have seen a very helpful answer here: https://stackoverflow.com/a/38781027/5201771 --> there, the author addresses how to solve this problem for the case of a single property (e.g., only "A" has value "foo", so require "C").
However, I currently don't see how to extend that answer to my case, where several properties determine the outcome.
Example Files
for illustration, I supply some files that should pass or fail the validation:
should pass:
{
"A": "bar"
"B": "baz"
}
{
"A": "foo"
"C": "some value"
}
{
"A": "bar"
"B": "foo"
"D": "some value"
}
should fail:
{
"A": "foo"
"B": "foo"
"D": "some value"
}