I don't undertstand why my json is formatted the wrong way

Hey guys ! i am running n8n from selfhost and i’m loving it. I just seem to not understand something in the way the Read file is working and it’s frustrating me.

My problem is simple i read data from a file on my server that looks like this :

And i want to take all these datas to format them but for some reason i can’t use {{ $json.test.id }} when i drag the id field it forces me to use {{ $json.test[0].id }} (picture shown here)

How can i get rid of the key so it goes through all the ids fields and not only the first one ?

(sorry if i’m unclear i’m not english native i’m happy to ellaborate if it’s unclear)

thanks!!

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Jean_Saucisse

How are you getting the data? It seems from the images that when you extract it, it is returning it as a single item so when you try to select it in your set node, it will only ever select [0] as that is the only item it can select.

You could try to reconfigure how the data is created in the file it is coming from to return it correctly as multiple items or try and use a Split Out node after the Extract from File node to see if that can take the single item and return it as multiple items to achieve what you are looking for.

I’m assuming (as I can’t see it) that your data after extraction looks like this:

[
{
"test": 
[
{
"id": 
3996,
"sequence": 
null
},
{
"id": 
4001,
"sequence": 
null
},
{
"id": 
4002,
"sequence": 
null
},
additional lines....
]
}
]

If that is the case, use the Split Out node after the Extract from File and drag test into the Fields to Split Out and that will turn the single item into multiple items.

If this is not how it looks, can you provide an example of the full JSON after it is extracted.

2 Likes

The JSON where i was getting the data was indeed formatted as you shown! I used the split node as you said and it is working perfectly !

Thanks for saving my day ahah

1 Like

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