Mutual Dependency
To understand mutual dependency, consider a JSON Document has two properties firstName and lastName
If both of these properties are mutually dependent, then both of the below conditions must be satisfied:
- If firstName is present, then lastName must also be present.
- If lastName is present, then firstName must also be present.
Similar to the previous lesson, we can use the dependentRequired keyword to enforce this mutual dependency.
Example Schema
1{ 2 "type": "object", 3 "properties": {...}, 4 "dependentRequired": { 5 "firstName": ["lastName"], 6 "lastName": ["firstName"] 7 } 8}
Task
1{ 2 "name": "John Doe", 3 "creditCardNumber":"1234 5678 1234 5678", 4 "address":"123 Main St", 5}
You are given a Schema for the above JSON document in the side editor. Update the schema to make sure that creditCardNumber and address are mutually dependent.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output