Flatten Merge output to single JSON item

First off, please be nice. I’m creating my first workflow in N8N - I feel like this is probably easy but I just cannot wrap my head around it!

Describe the issue/error/question

I’m creating a workflow which collects some input from a form and generates a powershell script - to automate user account creation. I’m doing some logic checking and generating a password in parallel, merging the final data again prior to handing off to a sub-workflow.

When I merge the data from my separate entries, I get a JSON array with 3 sets of data (shown below). I want this to be just a single, simple JSON payload in a single list.

What is the error message (if any)?

Please share the workflow

Share the output returned by the last node

Output given (‘Merge all info’ node):


[
{
"pwd": "vqhk7KJzIWxL"
},
{
"upn": "[email protected]"
},
{
"firstname": "Test",
"surname": "User",
"displayname": "Test User",
"jobtitle": "Specialist",
"department": "My Department",
"office": "AU Office",
"region": "Asia Pacific",
"country": "Australia",
"company": "My Company",
"phone": "",
"startdate": "2022-11-29",
"enddate": "",
"strengths": "",
"manager": "Fred Smith"
}
]

Desired Output:


[
{
"pwd": "vqhk7KJzIWxL",
"upn": "[email protected]",
"firstname": "Test",
"surname": "User",
"displayname": "Test User",
"jobtitle": "Specialist",
"department": "My Department",
"office": "AU Office",
"region": "Asia Pacific",
"country": "Australia",
"company": "My Company",
"phone": "",
"startdate": "2022-11-29",
"enddate": "",
"strengths": "",
"manager": "Fred Smith"
}
]

Information on your n8n setup

  • n8n version: 0.203.1
  • Database you’re using (default: SQLite): Not sure.
  • Running n8n with the execution process [own(default), main]: Not sure
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @Tom_Anderson, welcome to the community :tada:

Merging can be painful. I am sure we can figure this out though :slight_smile:

It seems you have three different items following your workflow but only want one. Assuming each of your individual branches only returns a single item, you would only need to switch the operation mode of your merge nodes.

Right now, you are using the “Append” mode. This will simply combine two lists into one larger list (so if you have 1 item on each input branch, you’d have 1 output branch with 2 items following the node). What you probably want to use instead is the “Combine/Merge By Position” mode:

image

This mode would merge the first (and in your case only) item of input one with the first item of input two. So, if you have 1 item on each input branch, you’d also have 1 output item with the properties of each of your input items.

I hope this makes sense and helps! Let me know if you have any questions on this.

Thanks!
Yes, this works - as does Multiplex which I eventually figured out how to use late yesterday. For some reason I hadn’t been able to find these options!

1 Like

Awesome, glad to hear you figured it out!

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