I have been looking around a lot, and can't find a simple answer to my problem, I have seen how to do searching and things with LINQ to JSON (that seems to complex for my needs).
I am using n8n.io to try to execute a "WebHook Post" -> Function call -> Split to Batch (1) -> API Call
I have a JSON Object like this
$json = {
"_id": "627bd2378b8bbe5c27a23669",
"firstName": "John;Maria;Bruce",
"lastName": "Doe;Phenix;Mclean",
}
I need to send each of these as 3 individual JSON objects to another webhook
I am trying to figure out a for loop that could take $json
and turn it into $json[0]
, $json[1]
, $json[2]
Where
$json[0] = {
"firstName": "John",
"lastName": "Doe",
}
$json[1] = {
"firstName": "Maria",
"lastName": "Phenix",
}
$json[2] =
"firstName": "Bruce",
"lastName": "Mclean",
}
I am having the hardest time finding the simplest and quickest way to go from A -> B any advice n8n.io allows me to take the $json.body from a previous step and process it with a javascript function?
Hoping there is some built-in method that can handle this translation in a step or two inside a for loop in Javascript.
//iterate through the combined JSON Object
for (var k of $json) {
//grab the row and split the string into 3
String.split($json[k]);
//Create a $newObj with a full set of data in each index
}
return $newObj
Big thanks to @metdodrbic for pointing me in the right direction.
His code worked 100%
I did have to edit the $json to $json.body because of the peculiar way n8n.io returns the JSON object from a previous step into the "function" block