Reputation: 673
Let's say I have the follow Json Schema
{
'type': 'object',
'properties': {
'MinimumNumber': {'type':'number'},
'MaximumNumber': {'type':'number'}
},
'required': ['MinimumNumber', 'MaximumNumber'],
'additionalProperties': false
}
How do I validate that the value of MaximumNumber is higher than the value of MinimumNumber?
invalid object
{
MinimumNumber: 10,
MaximumNumber: 5
}
valid object
{
MinimumNumber: 5,
MaximumNumber: 10
}
Upvotes: 4
Views: 1550
Reputation: 8428
@Ether is correct in saying that there is no solution for this with pure JSON Schema. However, there are now vocabularies. I've written one that allows you do just this.
Currently there's only my .Net implementation, but as draft 2020-12 is adopted, this may see more use across implementations in other frameworks.
Upvotes: 1
Reputation: 53996
This is a frequently asked question, but no, there is no way in JSON Schema to compare one section of your data against another section. You can do it manually by editing your schema to contain a portion of your data, e.g. via a template.
Upvotes: 1