Parsing Json items

I have http request body which I would like to extract the key values and send it in email body.
Could I please get help in parsing this. I need the following output so I can include it in the email.

[email protected], User added
[email protected], User already exist

request body (input)

“body”:
[
{
“success”:true,
“user”:“[email protected]”,
“statusMessage”:“User added”,
“requestId”:“1”
},
{
“success”:false,
“user”:“[email protected]”,
“statusMessage”:“User already exist”,
“requestId”:“1”
}
]

Thanks

Hi @Apsar_Rahman,
welcome to our community :wave:

I attach a workflow that shows how to do what you need:

The Set Node “set two fields in a single field” merges the incoming separate fields into a single one.
Then the Code Node “build final string” runs some javascript to create the final string, which is then used in the Send Email Node (you can use that string in any Node you need).

Depending on how proficient you are with javascript, you could also probably do everything with just the Code Node.

I hope this solves your problem, let me know if you need more help.
All the best

2 Likes

Thanks @giulioandreini.

Based on your solution, I worked out with just the code node with the below code. One question, In code node how do I access data from other node that are not immediately before this
For example, what will be the eqivalent of

{{ $node["Approve Webhook"].json["body"]["0"]["requestId"] }}
let finalString = "";
console.log($input.first().json.body)
for (let i = 0; i < $input.first().json.body.length; i++) {
  finalString += $input.first().json.body[i].user + " - " + $input.first().json.body[i].statusMessage;
  // Adds a line break after all elements expect the last one
  if(i < $input.first().json.body.length - 1 ) finalString += "<br><br>";
}

return [{"result":finalString}];

Hi @Apsar_Rahman,
to access nodes that are not immediately before the code node you can use this syntax:

$('Name of the node')

this will give you access to the data coming from the node named “Name of the node”.
Hope it helps.
Please paste here your workflow if you need more support (easier for me to help you :wink:).

Best

2 Likes

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