json check for empty elements and skip other non-mandatory fields in extract variable.

Hi There,

I have a JSON request(see below payload) which contains over 30 elements/fields out of the 20 are mandatory elements to pass. I want to check that 20 elements exist before I make a call to backend. If one of the mandatory elements not found wanted to RaiseFault with bad input. The other case is, let say if LastName element doesn't exist wanted to skip it from extract variables. Eventually, I will create an object and will send all the variables that are assigned extracted values to the backend as a myrequest obj.(var myrequestObj={}, will get and set the values to obj from extract variables assigned and pass it the blackened service)

Note: doesn't care about the empty values inside the element just want to check elements names only.

{

"firstName": "testfName", //element name firstName is mandatory to pass doesn't care about the value whether its empty or not.

"LastName" : "Lname", //optional

"email": "test@gmail.com", // mandatory

"pincode": "33434" //mandiitory

}

extractv

ar.png

0 5 1,172
5 REPLIES 5

It looks like you should write use a javascript policy to support your custom validation and json manipulation

cool, I can do that with javascript, but just checking with apigee experts opinion before I do that with js .thanks.

Yes, I'd do it that way.

you can specify the mandatory params in your API Schema using tv4.js
check this answer:
https://community.apigee.com/questions/78880/json-schema-validation.html?childToView=79016#answer-79...

Not applicable

You can have two extract variable policies. One with all mandatory fields and ignore unresolved variables false, and the second extract variable policy with non mandatory fields having ignore unresolved variables true.