Merge by Key Example

Can you please provide an example of how to use the MERGE node, specifically with the “Merge by Key” option?

I have two sets of data below as an example. How do I setup the merge by key node to match data[].interviewers[].id from Input 1 (e.g. 111222333) with the fields.eid in Input 2 and combine the data wherever there is a match?

Thanks!

Input 1 Data:

{
“data”: [
{
“pointer”: “12345”,
“panel”: “234234”,
“subject”: “Blah Blah”,
“note”: “”,
“interviewers”: [
{
“id”: “111222333”,
“name”: “Bobby Johnson”,
“email”: “[email protected]
}
],
“timezone”: “America/Los_Angeles”,
},
{
“pointer”: “98754”,
“panel”: “3243234”,
“subject”: “Yadda Yadda”,
“note”: “”,
“interviewers”: [
{
“id”: “444555666”,
“name”: “Billy Johnson”,
“email”: “[email protected]
}
],
“timezone”: “America/Los_Angeles”,
},
],
“hasNext”: false
}

Input 2 Data:

[
{
“name”: “test”,
“fields”: {
“FirstName”: “Bobby”,
“LastName”: “Johnson”,
“JobTitleDescription”: “Recruiter”,
“HomeDepartmentDescription”: “Recruiting Team”,
“Photo”: [
{
“x”: “attPuc6gAIHUOHjsY”,
“url”: “http://urlto.com/BobbyPhoto.jpg”,
“filename”: “photo.jpg”,
“size”: 28956,
“type”: “image/jpeg”
}
],
“eid”: “111222333”
},
“createdTime”: “2019-09-23T04:06:48.000Z”
},
{
“name”: “test2”,
“fields”: {
“FirstName”: “Billy”,
“LastName”: “Johnson”,
“JobTitleDescription”: “CEO”,
“HomeDepartmentDescription”: “Boss Team”,
“Photo”: [
{
“x”: “attPuc6gAIHUOHjsY”,
“url”: “http://urlto.com/BillyPhoto.jpg”,
“filename”: “photo.jpg”,
“size”: 28956,
“type”: “image/jpeg”
}
],
“eid”: “444555666”
},
“createdTime”: “2019-09-23T04:06:48.000Z”
}
,
{
“name”: “test3”,
“fields”: {
“FirstName”: “Susan”,
“LastName”: “Smith”,
“JobTitleDescription”: “CFO”,
“HomeDepartmentDescription”: “Boss Team”,
“Photo”: [
{
“x”: “attPuc6gAIHUOHjsY”,
“url”: “http://urlto.com/SusanPhoto.jpg”,
“filename”: “photo.jpg”,
“size”: 28956,
“type”: “image/jpeg”
}
],
“eid”: “777888999”
},
“createdTime”: “2019-09-23T04:06:48.000Z”
}
]

Hello,

very sorry for the late answer. I started to answer this morning. Then I realized that it did not work (as dot-notation was not supported) and got then sidetracked.

Fixed it now with that commit:
https://github.com/n8n-io/n8n/commit/3c8946ba7dd30507786bd23b6064cc50c0b5a593

I will try to release a new version with that fix later and then comment here again.

Ok is done. [email protected] is released. The new docker images should also be ready in a few minutes.

Here now the example of how you can make it work. You can simply copy the code below, click once into the n8n window and then paste it (CTRL + v). It will then create all the nodes and connections.

The “Data 1” and “Data 2” nodes simply mock the data you supplied. You can replace them with the data sources. Then the “Convert Data” nodes are important. They make sure that the different array items are actually different items in n8n (want to create nodes in the future to make that simpler so that no JavaScript code has to be written for it). After that, you have then the merge with the merged data.

1 Like

Works like a charm! Thanks Jan for your fast response with an accurate working example. This is just what I needed. You’re the man!

PS - Might I suggest adding your json solution (and others) to the “workflows” section of your website? I was looking at the merge description under the nodes section of your website and at the bottom it has no associated workflows. It might help others who want to learn how to use that node if this example workflow is listed there.

Thanks again nice work I like what you’re doing!

Really great to hear that it works!

Yes you are right. I really have to add some example workflows. Would make it much easier for people. Hope I get to it soon. Try to at least add a simple version of this once I am home.

I just posted this example workflow for you. Thanks for your awesome product.

EXAMPLE WORKFLOW: Merge by Key

Cheers!

1 Like

Great, thanks a lot!