Merge 2 items together with multiple arrays

Describe the problem/error/question

I am trying to merge new data into an existing JSON object. My item outputs generate the same JSON structure with just different lists I am trying to append to an existing list (Item 1 in a merge?)

I haven’t been able to find an obvious way to append this. I have tried all variations of merge with no luck. Can anyone suggest something?

Please share your workflow

Information on your n8n setup

Latest official docker

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:
  • n8n version:
  • 1.65.2
  • Database (default: SQLite):
  • Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Docker Official
  • Operating system:
  • Docker Official

You can try splitting out the questions with the Split Out Node combine it and then at the end aggregate it and then configure the output json.

Hmm, I was afraid that might be the case. The object has a variable number of these arrays (from 1 to 7). I was hoping I avoid building too much dupe functionality.

There is probably also another solution. I was just checking it while being on the train. In theory there is also the code node.

Can you tell me more about your workflow? At the moment you have 2 nodes which both output some json object. if you say the number of the arrays is varaible. How do you get the input data?

I simplified the example since I assumed whatever I learned here I could use if additional arrays were in place.

The example shows questions [1,2,3] and [4,5,6]. The goal would be to have them combined into [1,2,3,4,5,6].

In theory an additional array might be newArray= [object 1, object 2, object 3] and [object 4, object 5, object 6], so the goal would be to also combine those as seen above.

This is what I thought.

How aout this

to merge objects they need to have different name. In this case we need to check where the data gets changed within the objects. In your case I split out the questions and then merged it and then append it to the input json structure. Maybe this does help you.

So I added 2 ways .

Thanks so much, I landed somewhere close to what you created, and I will need to create a loop to go thru each array.

I am also trying to see if there’s something more elegant with with Javascript, but I haven’t found one quite yet!

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