Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Schema: Element is valid based on another element's value

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

like image 468
Deleteman Avatar asked Aug 12 '13 14:08

Deleteman


1 Answers

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.

like image 159
cloudfeet Avatar answered Sep 19 '22 17:09

cloudfeet