Ah yes, we have to return an object but we are returning a string. Without replicating the output it is a bit difficult for me to provide a solution that can be used in the Function node. Did you try with the other solution that involves using the Set node?
Yes, that is the only way we can code an example without knowing how your data looks like and how you want it to be transformed. The only example you had above showed only some numbers and was so totally different to what you post now.
Considering that the format is probably different for each row (and you seem to have very many different ones) I do have to suggest hiring someone who can program JavaScript to take care of that part for you.
If I could afford to pay someone to do the work, I wouldn’t be here struggling to get it done. I do appreciate all the help you have given so far. I won’t bug you again.
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 };
})
If there is a an object with a data structure you want to convert but you can not figure out yourself, post an example of it here (how data looks now and how you want it to look like), we should then be able to to help you to create it.