Hello. Help to find solution to transform json to new json

Hello everyone.
I have a json file on self-hosted
For example:
[
{
“firts_name”:“Tomas”,
“last_name”:“Green”,
“bio”:“main”
},
{
“firts_name”:“Serg”,
“last_name”:“Black”,
“bio”:“second”
}

I using the node Read File from Disk, next I use node Exctract From File and get

[
{
“data”: [
{
“firts_name”: “Tomas”,
“last_name”: “Green”,
“bio”: “main”
},
{
“firts_name”: “Serg”,
“last_name”: “Black”,
“bio”: “second”
}
]
}
]

node Exctract From File adds new list ‘data’. I do need this.
Question.
How to get origin json without nested ‘data’
[
{
“firts_name”:“Tomas”,
“last_name”:“Green”,
“bio”:“main”
},
{
“firts_name”:“Serg”,
“last_name”:“Black”,
“bio”:“second”
}

I tried Filter Fields node, I can not do it.
Please help me

Information on your n8n setup

  • **n8n version:1.94.1
  • Database (default: Postgres):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via Docker: selfhosted

Access the data array within the first input item (items[0].json.data).

Generates a new item for each element in the data array, which is what n8n expects as standard output.

The code node code would be:

const output = [];

for (const item of items) {
if (Array.isArray(item.json.data)) {
for (const entry of item.json.data) {
output.push({ json: entry });
}
}
}

return output;

followed by the node you will have the expected format

2 Likes

Thanks you very much.

1 Like

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