Serializing multiple inputs vs. multiple branches

Describe the question

I’m wondering about the proper approach to serialize single input coming from multiple branches vs. multiple inputs coming from one branch. The data input itself is conditional, because not all branches are running at the same time. The following screenshot is an example of single input coming from multiple branches:

In the example above, the first aggregation (after set fields) is intended to serialize the inputs from the set field node; the output is parsed as data field. The second aggregate combine all individual fields from the data field. The third aggregate is intended to again serialize the second aggregate node’s result.

And below is an example of multiple inputs coming from a single branch:

In this example, the first serialization works. It makes me wonder, why the second serialization (the third aggregation node) does not work. I have read Merge multiple Inputs and Best practice to wait for multiple branches before continuing? , which suggested the merge node. Merge node is not usable in my case because the branches are conditional, i.e., only selected branches are active at one time.

Please share your workflow

Share the output returned by the last node

The current output is separated into two objects. The first object:

[
  {
    "results": [
      {
        "data": [
          [
            {
              "PractitionerRoleID": "DGWADAG4GTWJS7US",
              "Specialty": [
                "Statistics",
                "Clinical Research",
                "Complex Modelling",
                "Public Health"
              ],
              "Availability": {
                "mon": {
                  "start": "08:00",
                  "end": "10:00"
                },
                "tue": {
                  "start": "09:00",
                  "end": "14:00"
                },
                "wed": {
                  "start": "10:00",
                  "end": "12:00"
                },
                "thu": {
                  "start": "10:00",
                  "end": "14:00"
                },
                "fri": {
                  "start": "09:00",
                  "end": "12:00"
                },
                "sat": {
                  "start": "08:00",
                  "end": "12:00"
                }
              }
            }
          ]
        ]
      }
    ]
  }
]

The second object:

[
  {
    "results": [
      {
        "data": [
          [
            {
              "Name": "Aly Lamuri",
              "PractitionerID": "DGWAADRS3KC4WNIW"
            }
          ]
        ]
      }
    ]
  }
]

What I want is a single object containing all results:

[
  {
    "results": [
      {
        "data": [
          [
            {
              "Name": "Aly Lamuri",
              "PractitionerID": "DGWAADRS3KC4WNIW"
            }
          ]
        ]
      },
      {
        "data": [
          [
            {
              "PractitionerRoleID": "DGWADAG4GTWJS7US",
              "Specialty": [
                "Statistics",
                "Clinical Research",
                "Complex Modelling",
                "Public Health"
              ],
              "Availability": {
                "mon": {
                  "start": "08:00",
                  "end": "10:00"
                },
                "tue": {
                  "start": "09:00",
                  "end": "14:00"
                },
                "wed": {
                  "start": "10:00",
                  "end": "12:00"
                },
                "thu": {
                  "start": "10:00",
                  "end": "14:00"
                },
                "fri": {
                  "start": "09:00",
                  "end": "12:00"
                },
                "sat": {
                  "start": "08:00",
                  "end": "12:00"
                }
              }
            }
          ]
        ]
      }
    ]
  }
]

Information on your n8n setup

  • n8n version: 2.2.4
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own, main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu LTS

Hello @lamurian, welcome!

I don’t quite understand this,
I tried using some random test data with the Merge node and enabled the option “Include Any Unpaired Items”:

and I think the result looks fine:

Have you tried this option in Merge node in your use case?

Also, note that I renamed the Aggregate node’s “Put Output in Field” option to a unique value (other than data) for each node:

2 Likes

Ahh, you’re correct, I must have missed that option. Thank you, now it works properly!

2 Likes

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