How can I list object values for unknow amount of Array returned?

If I have array “data” from HTTP request, but it will return different amount of items everytime. After I split out this node, how to perform next step to use value under each object? For this example, list some values under data[0], data[1].
Thanks

After splitting out the data, attach a Loop Over Items node. This will allow you to repeat a process for each item separately no matter the amount.

Thanks, but Loop Over items need to specify number of batch. How to make it auto determine?

Thanks

or i shouldnt add split out and directly use loop over node on HTTP request node?

Depends on the data you are working with. If you don’t have more than one array, the Loop Over Items node would work perfectly in 1 Batches mode.

May I have some sample on this? Not sure how can I consolidate the values under each from array.

For example, if I just use this to split out the items then send message, it will send 2 seperate message. But I want to put 2 result together

first, then send 1 single message

May I have someone idea on this? Thanks so much

[
  {
    "data": [
      {
        "id": "1",
        "filename": "testfile1.jpg",
        "content_type": "image/jpeg",
        "content_id": "conten1",
        "content_disposition": "attachment",
        "size": 25666,
        "download_url": "http://test.domain/testfile1.jpg",
        "expires_at": "2025-11-13T04:43:12.561Z"
      },
      {
        "id": "2",
        "filename": "testfile2.jpg",
        "content_type": "image/jpeg",
        "content_id": "conten2",
        "content_disposition": "attachment",
        "size": 627365,
        "download_url": "http://test.domainltd/testfile2.jpg",
        "expires_at": "2025-11-13T04:43:12.563Z"
      }
    ]
  }
]

See if anyone can help with some sample workflow,

If having the data above, everytime the returning number of data is different. I want to generate all links with <a href=”data.download_url “>data.filename</a> in output

This workflow splits out the data you gave into separate items, and generates final links using the download_url field from each item.

Copy this workflow and run it – examine how data is passed and where it was separated.

Note: No matter how many items there are, they will be split into separate items and processed independetly.

2 Likes

Thanks so much, I got it working now. But your workflow will generate more than 1 output after “Loop Over items”. So I add another “Aggregate” node after looping done to gather returned final result for easier to put in the email being sent

One more question, for the variable (in your example, “final” at “Edit Fields1”), will it be cleared after every execution? so that it won’t consume RAM after executed? Or I need to put another “Set” node to clear that "final”

Thanks

1 Like

Variables in n8n are execution-based, meaning that every execution may hold different variables. Also, n8n drops past executions & clears the canvas when a new execution is triggered. You can still view past executions from Executions tab at the top of your canvas and reproduce them.

So after execution of the flow, those variable will also be cleared from RAM but no need to add another “Set” node to clear them out? Thanks

There are many ways to to this.

I prefer to use expression since you want to use it as message content in telegram

{{ $json.data.map(item => `<a href="${item.download_url}">${item.filename}</a>`).join('\n') }}

This expression will loop data and combined the download link you want.

o, so using this EDIT node, even no need the LOOP node?

1 Like

Yeah it doesn’t need to loop.

But it is just one of many ways to do it. You can choose the one you prefer

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