How to apply constraint on the basis of count of properties? #586
-
Hello experts, I am trying to write a schema that will validate json of this type
with constraints: I have used patternProperties to apply the constraint on key names (constraint 2)
But I dont know how to apply the constraint number 3 above. I don't want to make property "0" required unconditionally because that will interfere with my constraint number 1 so how can I specify that "if count of properties in Steps >0, property "0" is required" Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
This seem to work but I was hoping for a more elegant If-then solution
|
Beta Was this translation helpful? Give feedback.
-
You can use "if": { "minProperties": 1 },
"then": { "required": ["0"] } |
Beta Was this translation helpful? Give feedback.
It works. It expresses the constraint, "if there is at least one property (minProperties: 1), then the '0' property is required".
If this doesn't work for you, the validator you're using probably doesn't support the
if
/then
keywords.