Hello
I have the following array output
[
{
"class": "IN",
"host": "yz.4399fz.com",
"type": "A"
},
{
"class": "IN",
"host": "ysbaojia.com",
"type": "A"
},
{
"class": "IN",
"host": "yourlife-group.com",
"type": "A"
}
]
and I would like to parse it and merge the “host” field into a single field as such
[
{
"host": "yourlife-group.com, ysbaojia.com, yz.4399fz.com",
}
]
can you pls let me know if it’s possible to achieve it with n8n?
Hey @ja3four!
It is possible to achieve it with n8n! You can use the following code snippet in a Function node.
const tempArr = [];
for (item of items) {
tempArr.push(item.json.host)
}
const host = tempArr.join(', ');
return [{json:{host}}];
1 Like
Jon
3
Ah you beat me @harshil1712,
I ended up with…
var data = [{"class": "IN","host": "yz.4399fz.com","type": "A"},{"class": "IN","host": "ysbaojia.com","type": "A"},{"class": "IN","host": "yourlife-group.com","type": "A"}];
var hosts = [];
for (let i=0;i<data.length;i++) {
hosts.push(data[i]["host"]);
}
return [{json:{host: hosts.toString()}}];
2 Likes
Secretly I am competing against you
Anyways, thanks for sharing your solution as well. I completely forgot the .toString()
method.
3 Likes