jsonjsonschemajson-schema-validator

json schema validate the value of one property against the value of another property


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
}

Solution

  • 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.