Aggregating data without outputting as arrays

I am using the Aggregate node to combine the output of two other nodes.

I’m able to structure the data how I want it, except that every piece of data seems to have been added to an array.

So rather than outputting:

query: “string here”

it’s outputting:

query: [“string here”]


See here how the data in the output is all after “0:” in each field.

How do I remove that and get it to output the data in the same way it is formatted initially? I.e. if it’s an array, then it outputs as an array, but if it’s a string, it outputs as a string, rather than a string inside an array.

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:

I don’t think that’s how aggregate works. Aggregate takes multiple items and returns one item.

What you want to do is to use the merge node or the Edit Fields(set) node if you want to combine the output of previous nodes.

1 Like

Sorry I should have been more clear. I have used the Merge node before the Aggregate node, but it didn’t give me enough control to structure the data. It just merged both datas in a crude way. So I’m using Aggregate to try and structure the data, but even that isn’t giving me the right output.

I also tried Edit Fields (Set) as per your recommendation but it’s also outputting data over two items rather than combining into one output.

Here’s the workflow:

If you don’t want two items , don’t use the append method in the merge node, since it will append both inputs. Use one of the other merging methods.

Or you remove the merge node and just use the edit node. When you open the node, you can select the output of earlier nodes in the top left corner.

Hi @atwork1 - thanks for getting back to me.

I tried just the Merge node on its own with one of the other two options:

Combine: Requires a matching item (but nothing in the two items matches).

Choose Branch: Only outputs one item.

So I’m not 100% clear on how to achieve the correct combination using the Merge node.

I tried the Edit Fields node on its own. This time, the structure is correct, but the output is not getting the data from the original node - so there are a lot of null values:

Would you mind sharing an example workflow which demonstrates how you get it to structure the data in the correct way?

hi James,

regarding the merge node, you can try Merge By Position, if the Https node returns on item for each input item.
grafik

The edit node should work, the way you set it up. In your example your pinned data is “null”, did you test with different data?
grafik

Thanks, I tried the Merge option with “Merge By Position” and it looks like it might work, although the test data has two sets of “data” - and so it’s overwriting the first “data” with the second one (rather than merging). But that’s something I could probably fix.

Strange that the pinned data is null. This is the data I was using:

[
  {
    "method": "GET",
    "data": {
      "query": "Retrieve a summary of discussions around client",
      "email": "[email protected]",
      "startTime": "2024-03-22T00:00:00Z",
      "endTime": "2024-03-25T00:00:00Z"
    }
  }
]

Gentle follow-up in case anyone is able to help.

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