Can't extract body data from webhook

Hi all,

For some time today I’m trying to extract data from json received on webhook and can’t get it to work. I have searched the forum here, and some people had the same issue, but the solutions were for older version of n8n where code block did not exist yet. My Json looks like this (cleaned):

[
{
"headers":{
"host":"some.page.com",
"content-length":"791",
"accept-encoding":"gzip",
"cdn-loop":"cloudflare",
},
"params":{
},
"query":{
},
"body":{
"data":"{"verification_token":"123456789","message_id":"123456789","timestamp":"2023-04-02T13:59:23Z","type":"msg","is_public":true,"from_name":"Jo Example","message":"message"}"
}
}
]

I need to get to values of individual items in body.data, no matter what I do it does not work :confused:

OK, here is the code that does what I needed. If anybody else needs it.

const output = [];

// Loop over input items, parse the 'data' string, and extract the 'verification_token'
for (const item of $input.all()) {
  const parsedData = JSON.parse(item.json.body.data);

  // Add the parsed 'data' to the output array as a new object with 'json' key
  output.push({ json: parsedData });
}

// Return the output array with only the parsed data
return output;
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.