I'm trying to validate a json schema based on the relation between two elements of the json object.
According to the draft of JSON Schema: to validate elements a json with inter-depedant keywords:
4.2. Inter-dependent keywords
In order to validate an instance, some keywords are influenced by the presence (or absence) of other keywords. In this case, all these keywords will be grouped in the same section.
http://json-schema.org/latest/json-schema-validation.html#anchor9
My problem is that the draft, doesn't really say how to write the schema in order to provide that validation. What I need to do, is validate a json like this:
{ a: 1, b: 2}
When a is always lower or equal to b. Can this be done? How do I write the schema?
Thanks
What that part of the spec means is (for instance) that the "additionalItems"
keyword's behaviour depends on the "items"
keyword, so the two keywords are placed next to each other in the spec.
Unfortunately, this kind of comparative validation of two values is not possible in JSON Schema. All the value constraints are calculated independently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With