Inverting Validation with not

not keyword is used to invert the validation. If the instance is not valid against the subschemas, the document is considered valid.

1{
2  "name": "John Doe",
3  "age": 25,
4}

We want the age to be greater then or equal to 18. but it should not be 21. We can use not keyword to define this condition.

1{
2  "type": "object",
3  "properties": {
4    "name": {"type": "string"},
5    "age": {
6      "type": "integer",
7      "minimum": 18,
8      "not": {"const": 21}
9    }
10  },
11}

Task

1{
2  "name": "John Doe",
3  "age": 21,
4  "status": "active"
5}

Modify the schema given to you in the side editor to ensure that the document is valid if:

  • status is not null.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output