Drop/Ignore Fields if Matches List

Not sure exactly how to illustrate this in the title, so apologies if this doesn’t align with “Drop/Ignore Fields if Matches List”. I have a list of JSON items containing 4 fields with numbers that look like this. While at least one of these fields will exist, it’s likely that only 1 or 2 of them will be there, so I’ve included a second sample of data with only two fields.

{
"phonenumber":
"+15551112222",
"mobilenumber":
"+15552221111",
"mobilenumber2":
"+15552221234",
"homenumber":
"+15552227777",
"name":
"Happy User",
"emailaddress":
"[email protected]"
}
{
"mobilenumber2":
"+15552221234",
"homenumber":
"+15552227777",
"name":
"Happy User",
"emailaddress":
"[email protected]"
}

Separate from this, I have a list of clients with phone numbers, sample shown below.

{
"name":
"Main",
"client_name":
"Happy Customer",
"phonenumber":
"+15552221234"
}

What I need to do is compare each of the fields in the first set of data against the “phonenumber” field from the second set of data and drop just the field of data in the first set if it matches the second set. So, using the examples above, my two sample sets would end up looking like this:

{
"phonenumber":
"+15551112222",
"mobilenumber":
"+15552221111",
"homenumber":
"+15552227777",
"name":
"Happy User",
"emailaddress":
"[email protected]"
}
{
"homenumber":
"+15552227777",
"name":
"Happy User",
"emailaddress":
"[email protected]"
}

What I need to do is compare each of the fields in the first set of data against the “phonenumber” field from the second set of data and drop just the field of data in the first set if it matches the second set.

Hi @cleveradmin, this would require multiple Merge nodes (one for each possible field) when done with native n8n nodes, so the resulting workflow would be rather hard to read. It would do the job though I think:

Thanks @MutedJam, but either you misunderstood (less likely) or I wasn’t very clear (much more likely). It appears that this looks for a match and then merges it, but I’m almost looking for the opposite. Using the workflow you provided, I don’t care about “Mock data B” or keeping the data within. In fact, it would actually look more like this:

[
   {
      "phonenumber":"+15552221234"
   },
   {
      "phonenumber":"+15551112222"
   }
]

And if any of the numbers from “Mock data A” match any of the numbers from “Mock data B”, I want to completely disregard the matching name/variable from “Mock data A”. So, this:

[
   {
      "phonenumber":"+15551112222",
      "mobilenumber":"+15552221111",
      "mobilenumber2":"+15552221234",
      "homenumber":"+15552227777",
      "name":"Happy User",
      "emailaddress":"[email protected]"
   },
   {
      "mobilenumber2":"+15552221234",
      "homenumber":"+15552227777",
      "name":"Happy User",
      "emailaddress":"[email protected]"
   }
]

Should become this:

[
   {
      "mobilenumber":"+15552221111",
      "homenumber":"+15552227777",
      "name":"Happy User",
      "emailaddress":"[email protected]"
   },
   {
      "homenumber":"+15552227777",
      "name":"Happy User",
      "emailaddress":"[email protected]"
   }
]

And if any of the numbers from “Mock data A” match any of the numbers from “Mock data B”, I want to completely disregard the matching name/variable from “Mock data A” (…)

That sounds like we’re almost there though. If you don’t care about some of the fields you could use a Set node after each Merge node that only keeps the fields you’re actually interested in.

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