if-then keyword

Implication is a logical operation that states that if condition A is true, then condition B must also be true. or in other words A -> B (pronounced, A implies B)

You can use the if-then keyword to enforce this condition.

Consider an isFullTime Field. If isFullTime is true, then the salary field must be present.

1{
2  "name": "John Doe",
3  "isFullTime": true,
4  "salary": 50000
5}

You can use the if-then keyword to enforce this condition.

Example Schema

1{
2  "type": "object",
3  "properties": {...},
4  "if": {"properties": {"isFullTime": {"const": true}}},
5  "then": {"required": ["salary"]},
6}

Task

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

You are given the schema for the same JSON document in the side editor. Modify the schema to enforce the below condition:

  • If isStudent is true, then the age field must be present.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output