I would like to know if there is a way to validate a json payload in such a way that it checks if there exists only one of two or more optional keys as well as validate its contents? i.e. in the following payloads the first two should fail since the first one does not include "telephone1" key, the second one should fail since it includes both "telephone1" and "telephone2" keys, the third should fail because has less characters than 8 as well as it contains alpha characters and the fourth one should pass since it includes a single key i.e "telephone2" and it consists of only numbers and has a length of 8
Hi,
I would like to know if there is a way to validate a json payload in such a way that it checks if there exists only one of two or more optional keys as well as validate its contents? i.e. in the following payloads the first two should fail since the first one does not include "telephone1" key, the second one should fail since it includes both "telephone1" and "telephone2" keys, the third should fail because has less characters than 8 as well as it contains alpha characters and the fourth one should pass since it includes a single key i.e "telephone2" and it consists of only numbers and has a length of 8
Payload 1: (Should fail) { "name": "george" }
Payload 2: (Should fail) { "name": "george", "telephone1": "12345678", "telephone2": "87654321" }
Payload 3: (Should fail cause less than 8 characters and it contains alpha characters) { "name": "george", "telephone2": "ABC123" }
Payload 4: (Should pass) { "name": "george", "telephone2": "87654321" }
Thanks.