I want to validate a JSON schema where an object in a nested JSON response is optional but if the object comes the keys in that object should also come.
Sample Response :-
{
"id" : "1234",
"targetPhoneNumber" : "1234",
"paid" : { //optional
"units" : "asd", //mandatory if the paid object is coming
"amount" : 12.00 //mandatory if the paid object is coming
},
"date" : "2019",
"boolean" : false,
"transactionId" : "1234"
}
I need schema checks for these cases.
1) If the paid object is coming it should be a JSON object and should contains units as string and amount as mandatory. 2) If the paid object is not coming still the schema validation should pass.