How can we access nested JSON object elements in a Zapier Webhook?
I tried with javascript and json.parser and that’s not work for me
How can we access nested JSON object elements in a Zapier Webhook?
I tried with javascript and json.parser and that’s not work for me
Hi
Here is an example of my data.
I need some of the fields that inside “meta_data” Like “TransactionId” and CardHolderID.
If it is, then you can do processing inside the Zapier platform before it gets provided to the zap.
If not then what did your javascript/JSON.parse look like… I’m imagining a code step right?
I have been successful at using formatter steps to pull out specific values but it takes multiple steps and is inefficient at scale (split text on “TransactionId” use the second result, then split on “,” and get the first result, now you have your value of Transaction ID (in quotes)) but I’ve also done similar in javascript which is significantly more efficient.
Knowing if you are processing this inside the platform or in a zap will better inform the code suggestions.
Hi
Since this was a little while ago, I wanted to check in to see if you’d managed to solve this or whether you still needed help here. Please let us know!
I have this same problem with a webhook. The root data appears to be translated, but nested data seems to be in a blob field. Is this a problem with the source json block of data or with zapier? Answering some of the other questions above - I don’t control the source of the hook, but I can influence it, if that is the problem. Thanks for the help! -Adam
If so, you could run a code step like so:
And the output would be all of the obects in the JSON as values like so:
Code for copying:
let smooth = JSON.parse(inputData.nestedJSON);
output = t{value: smooth}];
Interesting solution. It isn’t an actual blob. My Output from the hook is very similiar to the Output by the previous user. The top level fields seem to be definined; however sub record data is just key value pairs. I am trying to understand if this is just how zapier works or if the inbound JSON is not formatted properly.
I did try your soultion, but there is no single field out of the webhook object that is the entire dataset to input into the JSON parser, that I can find.
Example: stuff before and after:
here’s a snippet of that text
employee:{(stuff here)}
eventType:Job Booked
id: 400049721776
If it were proper JSON it would be formatted like this:
{
employee:{(stuffhere)},
eventType:'Job Booked',
id: 400049721776
}
So yeah you need to add commas and quotes as needed plus opening and closing curly braces { }
But if the original text had that Zapier would have parsed the JSON correctly.
This is a helpful tool I use to validate JSON, but it can be a little overzealous (has me quote all keys) https://jsonlint.com/
Awesome! Thanks for the help, explaining the json is invalid. I will go back to the originator of the webhook and see if they can fix it. -Adam
Hi there
I have a .json file with nested data being uploaded into an S3 bucket. This upload is the trigger for a zap and a number of posts to various endpoints. Is it possible to use JSON.parse or a variation to extract the data within the file for use later on in the Zap?
If not possible using a code step, is there another way I should approach this?
Many thanks
Joe
Just wanted to jump in to summarize an answer here!
If the JSON coming from a webhook is valid, it should be possible to use JSON.parse in a Code by Zapier step to parse out the relevant fields as per PaulKortman’s post above.
If it’s not valid, you can try using Formatter (Text) actions to extract and split information out into separate fields but this would likely involve numerous additional steps and is less efficient than using a single code step.
To confirm whether the JSON is valid you can use a tool like JSONLint to validate it.
And for issues with parsing key value pairs specifically, TimS wrote an article in Community which explains how to do that:
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.