I have a request payload with multiple keys (about 20 to 30) like name, email, phone number, address etc and some of these are optional.
To validate those I use multiple if
/else
conditions and in some cases I need to include validation based on a dependent key too.
For example: If I have a value in the address
key, then values for the city
, state
and zip
keys are mandatory. In this scenario I have a bunch of if
/else
conditions in my code. Is there a way to minimize the if
conditions and improve my code?
I’m expecting to reduce the number of if
/else
conditions