I am using the following Json Schema validation package:
Using that validation package, I want to validate in the following scenario:
Fields -
A
,B
Validation Condition - If
A
value is sent thenB
is not required. IfB
value is sent, thenA
is not required. But we need at least one of both field values in the form.
Can anyone help me on this?
I am using the following Json Schema validation package:
https://github./hasbridge/php-json-schema
Using that validation package, I want to validate in the following scenario:
Fields -
A
,B
Validation Condition - If
A
value is sent thenB
is not required. IfB
value is sent, thenA
is not required. But we need at least one of both field values in the form.
Can anyone help me on this?
Share Improve this question edited Feb 16, 2017 at 6:30 Robby Cornelissen 97.5k23 gold badges150 silver badges175 bronze badges asked Feb 16, 2017 at 5:52 Vinoth BabuVinoth Babu 6,85010 gold badges40 silver badges56 bronze badges 4- You want to know how to write a JSON Schema that requires at least A or B? – Robby Cornelissen Commented Feb 16, 2017 at 5:56
- I cant see no code to help you debug. – Zim84 Commented Feb 16, 2017 at 5:57
- @RobbyCornelissen - Yes you are right – Vinoth Babu Commented Feb 16, 2017 at 6:01
- May i know why down vote? Could you please explain that and raise down vote? – Vinoth Babu Commented Feb 16, 2017 at 6:06
1 Answer
Reset to default 7This is a JSON Schema that tests for the presence of property A
and/or B
:
{
"properties": {
"A": {},
"B": {}
},
"anyOf": [{
"required" : ["A"]
}, {
"required" : ["B"]
}]
}
Whether or not your PHP library supports this syntax is a different matter since the github page states that [...] it is not yet feature plete.
Here's a screenshot of testing it against Newtonsoft's online JSON schema validator: