Multiplex merge: module behaviour combining data

Related to my other topic: Iterating over multiple arrays in a flow

Can someone elaborate on the actual behaviour of this “Merge - Multiplex” module? I have created the following flow:

The goal is to do subsequent HTTP posts from each item within the array, and then combining that data back together at the end.
However, I can’t find any information on how this merge module works. Does it combine the data back together in the proper way, with each item its subsequent data output in the right order?
Or would it mix up data when there are multiple items in an array?

Thank you!

Anybody who can shed some light on this module?
Would be very helpfull

Hi @Bjorn, maybe looking at a simpler workflow helps understanding how the Multiplex mode works. In the below example workflow, the Merge node will receive 3 items on input 1 and 2 items on input 2:

Example Workflow

The Merge node will now merge every single item from input 1 with every single item from input 2, returning a total of 6 items. If you were to place an HTTP Request node after the Merge node it would make 6 HTTP requests in total.

Thank you @MutedJam ! That’s greatly apreciated.

Still I can’t wrap my mind around it somehow. I need to make sure, that the workflow merges the data back together which matches each other (not sure if this makes it clear :sweat_smile:)

So lets say:
HTTP1 I need to get the companies:

[
	[{
		"Value": [{
				"Description": "",
				"Id": 3,
				"Name": "America AM",
				"Type": "Company"
			},
			{
				"Description": "",
				"Id": 4,
				"Name": "America PM",
				"Type": "Company"
			}
		]
	}]
]

Now for each item within value I need to run another HTTP to get the areas of each company. This outputs:

[
	[{
		"Value": [{
			"Description": "",
			"Id": 3,
			"Name": "Aggregates",
			"Type": "Area PM"
		}]
	}],
	[{
		"Value": [{
			"Description": "",
			"Id": 4,
			"Name": "Aggregates",
			"Type": "Area AM"
		}]
	}]
]

Now this data needs to be merged into an array again properly, not multiplied with each other.
So lets say area 3 comes from company America AM and area 4 comes from America PM. How do I combine this, into a JSON again so the data matches each other? Not multiply it.

Hope I make sense. Thanks again!

Oh I see - the Multiplex node would indeed make things more complicated in this case.

But let’s unpack this step by step. The first problem I see are the different data structures. Neither of the example outputs provided appear to be multiple n8n items which actually seems like a step back from where we previously were.

So based on my understanding (and please correct me if my assumptions are wrong at any point), this would be a three step process:

  1. First, let’s ensure that we have one n8n item per Value object as my understand is that these are the items you’d like to merge eventually.
  2. I’d then assign unique keys (field names/column headers if you like) to each field to avoid accidentally overwriting any data (I’ve just appended 1 and 2 to the existing names in my example, but you might want to pick more descriptive names on your side).
  3. Lastly, I’d merge the items based on their Id values using the Merge By Key mode of the Merge node.

Using your latest sample data this would give me two items in the end with fields from both branches (where the both items with Id 3 are merged together in one new item and both items with Id 4 are merged together in another item):

Example Workflow