I have some data coming in in json format with Zap.(Attached "Long Answer")
I want to use that json data in Code Step (JavaScript), but when I do JSON.parse, the test succeeds and the Zap execution fails.(Is the input format different between test and runtime?)
How can I get the contents of the incoming json data with inputData?
Best answer by mattc526
Hi Troy (and anyone else that might need this) I got it!
let myInputData = inputData.text;
let finalData = "";
if (myInputData != null) {
finalData = {"result" : JSON.parse(inputData.text).name};
} else {
finalData = {"result" : ""};
}
output = finalData;
This code is when metadata comes over from stripe and needs to be parsed ONLY when the metadata is present. If the metadata isn’t there, then the output is empty. If it is there, then we output only the “name” that comes from the json array from stripe. Hope that helps!
Does the inability to accept an object mean that I can't refer to the value from another step as shown in the image? Or does it mean that the value entered in the Long Answer field is unacceptable due to the json format?
in your screenshot, it looks like Zapier has already parsed the object Long Answer and in the next zapier steps you will have data fields like Long Answer object, Long Answer id, Long Answer lead_price, etc…
You will need to map the individual fields unless you rebuild or have access to the raw json from the previous step
Question - how do we include error checking in that code above? My zap keeps stopping because there is no data in the object. Can you add some code that would just skip it if the data is empty?
I appreciate the speedy reply Troy! Only issue is that I want the zap to run no matter what. Filters are good for stopping the zap if a condition isn’t met.
Basically, sometimes there is data in the object, and sometimes there isn’t. Even if there isn’t data there, I need the zap to continue firing.
Hi Troy (and anyone else that might need this) I got it!
let myInputData = inputData.text;
let finalData = "";
if (myInputData != null) {
finalData = {"result" : JSON.parse(inputData.text).name};
} else {
finalData = {"result" : ""};
}
output = finalData;
This code is when metadata comes over from stripe and needs to be parsed ONLY when the metadata is present. If the metadata isn’t there, then the output is empty. If it is there, then we output only the “name” that comes from the json array from stripe. Hope that helps!