Describe the problem/error/question
If I receive data in a JSON - $json[“body”][“0”][“data I need”] - how can I numerically access (or iterate through) the items in “body”?
If there’s just one item, I know I can use “0”. But if there are 3 items for example, and each item contains an item called “data I need” how can I access these items numerically?
please share your workflow (or just a part of it) so that’s easier to provide a solution.
In the meantime, I suggest you to explore using the “Split Out Items” operation of the Items Lists node. This allows you to separate all the elements in
body and have them as separate n8n items. In this way you can easily treat them separately with each following node.
A quick example here:
I hope it helps!
Hi @giulioandreini !
Thank you for sharing this. This is a step in the right direction for me.
I implemented your example above, and got a JSON now with two items, named “John Doe” and “John Doe”. (I actually changed the first name to “Jane Doe” so I could distinguish them.) Let’s assume those are instead ID numbers, or the name values of the items that were previously in “body”.
How do I access or search those? Using your example (with my small modification) I can easily access the first item in JSON, “Jane Doe”. But that’s the only one I see… If I wanted to instead search for and use John Doe’s information, how would I do that?
Thank you for the insights!
what happens now is that the items in the
body array are split and will be sent as separate items in the following nodes:
So each following node will receive all the items separately.
To better answer your question I need to understand what you need to do in the following part of your workflow.