How to write merge node expression?

Hi guys, i play with n8n in the last 2 weeks, and I just realize how powerful it is.
but I’m stuck with merge node custom expression, it’s always giving me an error ''The workflow has issues please fix them first" merge parameter property input1 is required.

i just want to merge 2 json, and this is a really simple one

json 1 from previous node before merge node as input 1:
[{“json”: {“test”: “a”}}]

json 2 from previous node before merge node as input 2:
[{“json”: {“test”: “2”}}]

honestly I already success did this without custom expression, i just need to add merge node and set mode append and done.

But i really want to know how to use custom expression to do something like this, so i can customize it in the future, so guys, please give me an example how to write merge custom expression, thank you so much

Hi @Andrian, welcome to the community!

The Merge node wouldn’t usually need expressions. If you use, for example, the Merge By Key mode, you’d need to specify the name of the field you want to use to merge data.

So your items would need a shared key that can be used for merging such as an ID. Here’s a quick example showing the idea and merging items based on the name field:

Example Workflow

For data like the example you have shared you could simply use the Merge By Index mode. Using that mode, the first item from input 1 would be merged into the first item from input 2.

I hope this makes sense! Please do let me know if you have any further queries on this.


oooww Thank you Jam for the explanation about it, but honestly I don’t have an issue for the implementation from function node, but what makes me curious is, is there any syntax if I want to use it with expression builder?

as you can see in the image below, that’s what make me so curious how to write the expression it self let say just for merge by index mode, but with expression

Hi @Andrian, as a first step you might want to simply remove the expression to get the original dropdown back:

You can then simply select a supported mode.

In case you do want to use an expression, simply add a new expression after selecting a mode and you should see correct underlying value for each mode which you can re-use.

Hi @MutedJam thanks for reach me back, yeap i now how to add the expression, but my main question is could you tell me what the syntax will be look like, that’s my main goal : ), at least for really simple like merge both key from 2 different output, what I need to know is the syntax, so will not hit the ‘workflow cannot be executed’ warning like the previous screenshot.

at least for really simple like merge both key from 2 different output, what I need to know is the syntax

Have you tried using my example workflow from the initial response?

It would merge items from two different inputs based on a common key and will not produce any errors.

The syntax is simple:

I just used the name of the field in the property input fields. No expression needed.

@MutedJam thanks for always helping your new noob member :joy:, and yeah already tried too, but what I make to keep curious about expression is, because I cannot find mode Merge By Key, Multiples, Passthrough, Remove Key Matches, Wait like in this doc link

I can only find 3 options, and it same with n8n .io, .cloud, even the mac desktop app, and i already using the latest version too.
please take a look at this screenshot, the option only Append, Keep Key Matches, and Merge By Index

Ohhhh, I see now! You should be able to simply scroll down to the additional modes after opening the dropdown:

This also came up in another conversation I had today but never before iirc and I know @sirdavidoff has already added this to our notes around the Merge node so we can keep this in mind during future development work.

@MutedJam ahhhhhh, okay so i need to add fake expression first, so when I tap the gear it will show remove expression, after that all the options appear, thank you so much @MutedJam.
Have a nice day, and stay healthy :slight_smile:

1 Like

You are most welcome. You wouldn’t need to add any expression at all though. When adding a fresh Merge node the dropdown of modes should already be available without having to deal with expressions.

1 Like