JSON Schema:元素基于另一个元素的值有效

Del*_*man 5 validation json jsonschema

我正在尝试基于json对象的两个元素之间的关系来验证json模式.

根据JSON Schema的草案:使用inter-depedant关键字验证元素json:

4.2.相互依赖的关键字

为了验证实例,某些关键字受其他关键字的存在(或不存在)影响.在这种情况下,所有这些关键字将分组在同一部分中.

http://json-schema.org/latest/json-schema-validation.html#anchor9

我的问题是草案,并没有真正说明如何编写架构以提供验证.我需要做的是验证像这样的json:

{ a: 1, b: 2}
Run Code Online (Sandbox Code Playgroud)

当a总是低于或等于b.可以这样做吗?我该如何编写架构?

谢谢

clo*_*eet 5

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.