# Trying to filter a json with another json

**URL:** <https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844>\
**Category:** Questions\
**Tags:** data-transformation, node, merge\
**Created:** [April 4, 2022, 2:27pm UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844 "2022-04-04T14:27:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gertz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gertz/32/12118_2.png) [@gertz](https://community.n8n.io/u/gertz)\
**Post date:** [April 4, 2022, 2:27pm UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/1 "2022-04-04T14:27:03Z")

</div>

## I am trying to filter a json with another json, to get the values which are present in both of them

## Please share the workflow

````auto
```{
  "nodes": [
    {
      "parameters": {
        "filePath": "/home/n8n/Download/vergleich.json"
      },
      "name": "Read Binary File",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        -20,
        60
      ]
    },
    {
      "parameters": {
        "filePath": "/home/n8n/Download/empirum.json"
      },
      "name": "Read Binary File1",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        -20,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const empirumImport = new Array ($items(\"empirumFunction\"));\nconst dellImport = new Array($items(\"dellFunction\"));\n\n\n\nvar haveDevice = dellImport.filter(function(dell){\n return empirumImport.filter(function(emp){\n return dell.Modell == emp.Name;\n\n })\n\n});\nreturn haveDevice;\nconsole.log(haveDevice);\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        540,
        140
      ]
    },
    {
      "parameters": {
        "options": {
          "encoding": "utf8"
        }
      },
      "name": "dellImport",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        120,
        60
      ]
    },
    {
      "parameters": {
        "options": {
          "encoding": "utf8"
        }
      },
      "name": "empirumImport",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        120,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const result = []\nfor (item of items) {\n for (json of item.json) {\n result.push({\n json: {...json }\n })\n }\n}\n\nreturn result"
      },
      "name": "empirumFunction",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        260,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const result = []\nfor (item of items) {\n for (json of item.json) {\n result.push({\n json: {...json }\n })\n }\n}\n\nreturn result"
      },
      "name": "dellFunction",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        260,
        60
      ]
    }
  ],
  "connections": {
    "Read Binary File": {
      "main": [
        [
          {
            "node": "dellImport",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Binary File1": {
      "main": [
        [
          {
            "node": "empirumImport",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "dellImport": {
      "main": [
        [
          {
            "node": "dellFunction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "empirumImport": {
      "main": [
        [
          {
            "node": "empirumFunction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "empirumFunction": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "dellFunction": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

````

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

```auto

## Share the output returned by the last node
<!-- If you need help with transforming the data, please also share the expected output -->
[

{

"json": {

"Modell": "Latitude 9520",

"Version": "A02",

"Link": "valid https link to dell website."

}

},

{

"json": {

"Modell": "Latitude 9510",

"Version": "A06",

"Link": "valid https link to dell website."

}

},

{

"json": {

"Modell": "Latitude 9420",

"Version": "A05",

"Link": "valid https link to dell website."

}

},

{

"json": {

"Modell": "Latitude 9410",

"Version": "A08",

"Link": "https://www .dell.com/s upport/kbdoc/ 000109721/la titude-9410 -window s-10-driver-pack"

}

},

{

"json": {

"Modell": "Latitude 7520",

"Version": "A03",

"Link": "valid https link to dell website."
 
}

},

{

"json": {

"Modell": "Latitude 7490",

"Version": "A15",

"Link": "valid https link to dell website."

}

},

{

"json": {

"Modell": "Latitude 7480",

"Version": "A15",

"Link": "valid https link to dell website."

}

}
]

]

The input data for dellFunction is as following:
[{
  "Modell": "Latitude 9520",
  "Version": "A02",
  "Link": "https://ww w. dell. com/supp ort/kbdoc/000184698/latitude-9529-wind ows-10-driver-pack"
}]

and for empirumFunction its this:
{
  "Name": "Latitude E5450",
  "Windows7": null,
  "Windows10": "Dell_Latitude_E5450_A08.CAB",
  "WindowsServer2016": null,
  "WindowsServer2019": null
}

## Information on your n8n setup
- **n8n version:** 0.169.0
- **Database you're using (default: SQLite):** SQLite
- **Running n8n with the execution process [own(default), main]:** own
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]:** truenas jail
```

---

<div class="post-metadata">

**Author:** ![gertz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gertz/32/12118_2.png) [@gertz](https://community.n8n.io/u/gertz)\
**Post date:** [April 4, 2022, 2:28pm UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/2 "2022-04-04T14:28:00Z")

</div>

Forgot to mention:  
The Models in the output aren’t filtered at all.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [April 5, 2022, 8:11am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/3 "2022-04-05T08:11:10Z")

</div>

Hi @gertz, welcome to the community 🎉

You could use a [Merge node](https://docs.n8n.io/nodes/n8n-nodes-base.merge/) in “Keep Key Matches” mode for this.

Simply specific the name of the property from each input you want to filter on like so:

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/a/a9762de2c64ec3f6a86429a5a6045b0e04fde8d0.png)

Afterwards, only the items present in both inputs should be passed on.

Example workflow:

If you need the full data from both sources, you can simply add another Merge node afterwards, this time in _Merge By Key_ mode. No code required (my Function nodes simply mock some data here since I don’t have your source files):

Hope this helps!

---

<div class="post-metadata">

**Author:** ![gertz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gertz/32/12118_2.png) [@gertz](https://community.n8n.io/u/gertz)\
**Post date:** [April 5, 2022, 8:45am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/4 "2022-04-05T08:45:46Z")

</div>

Hello MutedJam.  
Thank you for your input! That helped me a lot actually. 😃  
Got my head wrapped around the idea to use JS… got it working in vscode already, but not with the function node. 😅

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [April 5, 2022, 9:05am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/5 "2022-04-05T09:05:25Z")

</div>

Sweet, I am glad to hear this helped, thanks a lot for confirming!

As for the JS part, I think the [data structure](https://docs.n8n.io/getting-started/key-concepts/#data-structure) could be the problem in your Function node. You are checking if `dell.Modell == emp.Name`, however, your items probably don’t have a `Modell` or `Name` property. Instead they’d have `dell.json.Modell` or `emp.json.Name`.

The `json` property is hidden in the UI and no longer required when returning data, but you can see the full data structure in your browser console if you do something like `console.log(dell);`.

I hope this makes sense, give me a shout if I am unclear here.

---

<div class="post-metadata">

**Author:** ![gertz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gertz/32/12118_2.png) [@gertz](https://community.n8n.io/u/gertz)\
**Post date:** [April 5, 2022, 10:16am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/6 "2022-04-05T10:16:18Z")

</div>

Thank you so much! 🙂  
i’m literally learning javascript and json as i use n8n more. i learned programming at school, but thats already 10 years ago, and now i have to catch up. 😃

and i have to confess: its a lot of fun, to learn and make improvements. 🙂

---

<div class="post-metadata">

**Author:** ![dickhoning](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/dickhoning/32/10415_2.png) [@dickhoning](https://community.n8n.io/u/dickhoning)\
**Post date:** [April 6, 2022, 6:58pm UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/7 "2022-04-06T18:58:01Z")

</div>

@MutedJam when I copy and paste this workflow in my n8n, I get this:

 ![Screenshot 2022-04-06 at 20.57.17](https://europe1.discourse-cdn.com/n8n/original/2X/3/3aaff4913f06b8cefa6cabfe5ad55c6c12ce6f4e.png)

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [April 7, 2022, 6:58am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/8 "2022-04-07T06:58:18Z")

</div>

Hey @dickhoning, sorry to hear that. I just tried copying both of my example workflows from [Trying to filter a json with another json - #3 by MutedJam](http://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/3) again, but didn’t run into trouble here:

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/c/c26c7268d25294af7eaf6666beef72250c6a3dc6.png)

Wonder if this might have been any kind of temporary problem. Could you re-open your n8n window and try pasting this in a fresh workflow canvas?

---

<div class="post-metadata">

**Author:** ![dickhoning](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/dickhoning/32/10415_2.png) [@dickhoning](https://community.n8n.io/u/dickhoning)\
**Post date:** [April 7, 2022, 7:11am UTC](https://community.n8n.io/t/trying-to-filter-a-json-with-another-json/12844/9 "2022-04-07T07:11:32Z")

</div>

@MutedJam works fine when I copy it into a fresh workflow canvas, but not when I paste it into my (big/huge) data-transformation template/playground …
