Merge instead of discard, two elements of an array,

Working with Google People API, I’m possibly setting up to four phone numbers on a contact.

The merge nodes seem to discard elements instead of merging them under the array.

No error message, the data is just not there in the JSON.

My Workflow is in the comments

I had to post only part of it, and I was still bumping into the character limit.

Share the output returned by the last node

[
  {
    "contact": {
      "organizations": [
        {
          "name": "HRCC",
          "type": "work"
        }
      ],
      "emailAddresses": [
        {
          "value": "[email protected]",
          "type": "work"
        }
      ],
      "names": [
        {
          "givenName": "Millie",
          "familyName": "Guisto"
        }
      ],
      "phoneNumbers": [
        {
          "value": "(541) 386-2183",
          "type": "main"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFVOeE9YTFFLODhrPQ==",
    "id": 84
  }
]

Expected output

[
  {
    "contact": {
      "organizations": [
        {
          "name": "HRCC",
          "type": "work"
        }
      ],
      "emailAddresses": [
        {
          "value": "[email protected]",
          "type": "work"
        }
      ],
      "names": [
        {
          "givenName": "Millie",
          "familyName": "Guisto"
        }
      ],
      "phoneNumbers": [
        {
          "value": "(541) 386-2183",
          "type": "main"
        },
        {
          "value": "5414907176",
          "type": "home"
        },
        {
          "value": "5416789534",
          "type": "mobile"
        },
        {
          "value": "541-555-1212",
          "type": "work"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFdFRm0xT1ZyNld3PQ==",
    "id": 84
  }
]

Information on your n8n setup

  • n8n version: 1.52.2
  • Database (default: SQLite): postgresQL 15
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker on DO
  • Operating system: Ubuntu 22.04.4 LTS

My Workflow

Hi @russellkg ,

Both the actual output and the expected output you shared are the same. Could you share what you would expect?

I’ve tried to recreate using a simpler wf but I don’t get discarded data. It also seems that you’re not using the latest version of the Merge node, despite being on the latest version. Are you able to re-add the node and see if you can access the latest version?

Oh geez, I copied and pasted the same JSON… Here’s what comes out. Above is the expected JSON.

For clarity, on this contact, the input has two phone numbers. I would expect to have two phone numbers in the output for this contact. Main, and Home.

[
  {
    "contact": {
      "organizations": [
        {
          "name": "HRCC",
          "type": "work"
        }
      ],
      "emailAddresses": [
        {
          "value": "[email protected]",
          "type": "work"
        }
      ],
      "names": [
        {
          "givenName": "Millie",
          "familyName": "Guisto"
        }
      ],
      "phoneNumbers": [
        {
          "value": "(541) 386-2183",
          "type": "main"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFdFRm0xT1ZyNld3PQ==",
    "id": 84
  }
]

Changing the merge nodes out results in the same JSON:

Here is the specific output of the newer nodes:

[
  {
    "contact": {
      "organizations": [
        {
          "name": "HRCC",
          "type": "work"
        }
      ],
      "emailAddresses": [
        {
          "value": "[email protected]",
          "type": "work"
        }
      ],
      "names": [
        {
          "givenName": "Millie",
          "familyName": "Guisto"
        }
      ],
      "phoneNumbers": [
        {
          "value": "(541) 386-2183",
          "type": "main"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFdFRm0xT1ZyNld3PQ==",
    "id": 84
  }
]

Both the Home Phone and Main Phone paths produce a “phoneNumbers” array.

Home:

[
  {
    "contact": {
      "phoneNumbers": [
        {
          "value": "5414907176",
          "type": "home"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFdFRm0xT1ZyNld3PQ==",
    "id": 84
  }
]

Main:

[
  {
    "contact": {
      "phoneNumbers": [
        {
          "value": "(541) 386-2183",
          "type": "main"
        }
      ]
    },
    "contactId": "c4008784378240636952",
    "resourceName": "people/c4008784378240636952",
    "etag": "%EgwBAgkLDBAuNz0+P0AaBAECBQciDFdFRm0xT1ZyNld3PQ==",
    "id": 84
  }
]

Thanks for looking at this.

-Russ

Yes, seems the merge node is not able to merge nested arrays

A shorter example with the issue:

OK. Between the three of us, I gathered enough of a solution to put this together. It appears to work.

Thanks a lot everyone!

-Russ

2 Likes

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