In this case, is it sadly very hard for us to help you. The reason is that you have a complex task to solve but the provided data is incomplete which makes it impossible for us to do so. The only way I see forward, is to provide you one more generic example that you can then change and extend.
Hope it is helpful!
Here the code of the Function-Node:
const results = []
for (const item of items) {
results.push.apply(results, item.json.reports)
}
return results.map(element => {
const json = {};
for (const key of Object.keys(element)) {
// Assume that is one thing you want to do. to have instead of "[1,2,3]" just "1, 2, 3"
if (key === 'classification') {
json[key] = element[key].join(', ');
continue;
}
// Replace "noIdea" with the actual name of the row from your previous example
if (key === 'noIdea') {
json[key] = element[key].map(data => data.name).join(', ');
continue;
}
// You can add copy the if`s and then change the data accordingly
// All others that are not specifically set will fall back to the default logic
json[key] = typeof element[key] === 'object' ? JSON.stringify(element[key]) : element[key];
}
return { json };
})
Here the example workflow with the mocked data:
{
"nodes": [
{
"parameters": {
"functionCode": "items[0].json.reports = [\n {\n justString: \"myString\",\n justNumber: 3,\n classification: [1,2,3],\n noIdea: [{\"id\":\"111\",\"name\":\"TAGRESULT1\"},{\"id\":\"222\",\"name\":\"TAGRESULT2\"},{\"id\":\"333\",\"name\":\"TAGRESULT3\"},{\"id\":\"444\",\"name\":\"TAGRESULT4\"},{\"id\":\"555\",\"name\":\"TAGRESULT5\"}]\n }\n];\nreturn items;"
},
"name": "Mock Data",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
450,
300
]
},
{
"parameters": {
"functionCode": "const results = []\nfor (const item of items) {\n results.push.apply(results, item.json.reports)\n}\n\nreturn results.map(element => {\n const json = {};\n for (const key of Object.keys(element)) {\n // Assume that is one thing you want to do. to have instead of \"[1,2,3]\" just \"1, 2, 3\"\n if (key === 'classification') {\n json[key] = element[key].join(', ');\n continue;\n }\n // Replace \"noIdea\" with the actual name of the row from your previous example\n if (key === 'noIdea') {\n json[key] = element[key].map(data => data.name).join(', ');\n continue;\n }\n // You can add copy the if`s and then change the data accordingly \n \n // All others that are not specifically set will fall back to the default logic\n json[key] = typeof element[key] === 'object' ? JSON.stringify(element[key]) : element[key];\n }\n return { json };\n})\n"
},
"name": "Transform",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
650,
300
]
}
],
"connections": {
"Mock Data": {
"main": [
[
{
"node": "Transform",
"type": "main",
"index": 0
}
]
]
}
}
}