I have below JSON ,
[
{
"name":"john",
"school":"school 2",
"address":"newyork"
},
{
"name":"peter",
"school":"school 1",
"address":"washington"
}
]
here i want to validate below mentioned things,
1 – it should be an array
2 – it must have only 3 fields (name,school,address) not more that or less than these three fields
3 – "school" can be either ‘school1’ or ‘school2’ and "address" can be either "newyork" or "washington"
I amneed to do this using react js and javascript
Thanks in advance
2
Answers
Here is a simplified function of what you are trying to do
then just use
const isValid = validateJSON(json);
Validation using
yup
and validate,
Note: this validation is not tested