Merge two items into one with new properties (array)

Describe the problem/error/question

I’m basicially having two items which i fetch from a website using one HTTP Request and i split that Request into two HTML elements, which i want to combine at the end to a specific JSON Model into one item.

The problem here is, that i’m having two different arrays which i want to combine:

JSON of Input 1 (date):

[
  {
    "date":[
      "21.04.2023, 19:30 Uhr",
      "12.07.2023, 20:00 Uhr",
      "24.06.2023",
      "21.07.2023, 19:30 Uhr"
    ]
  }
]

JSON of Input 2 (title)

[
  {
    "title":[
      "Topic 1",
      "Topic 2",
      "Topic 3",
      "Topic 4"
    ]
  }
]

My target is to comine them as the following (the fetched date is not always perfect):

    {
        "events": [
            {
                "date": "21.04.2023, 19:30 Uhr",
                "title": "Topic 1"
            },
            {
                "date": "12.07.2023, 20:00 Uhr",
                "title": "Topic 2"
            },
            {
                "date": "24.06.2023",
                "title": "Topic 3"
            },
            {
                "date": "21.07.2023, 19:30 Uhr",
                "title": "Topic 4"
            }
        ]
    }

I was trying with Item Lists, Merge and also Code with e.g. concat but the result is not what i’ve expected. Maybe you can help me out here :slight_smile:

Please share your workflow

Share the output returned by the last node

[
  {
    "title":[
       "Topic 1",
       "Topic 2",
       "Topic 3",
       "Topic 4"
    ]
  },
  {
    "date":[
      "21.04.2023, 19:30 Uhr",
      "12.07.2023, 20:00 Uhr",
      "24.06.2023",
      "21.07.2023, 19:30 Uhr"
    ]
  }
]

Information on your n8n setup

  • n8n version: 0.222.3
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Debian 11

Hi there,

You could try with a combination of Item List node to split the items, and Set node to combine them in a new object.

Here is an example:

1 Like

Hey @romain-n8n! :slight_smile:

Thanks a lot! I could get it working, just my set looks a bit different and i actually don’t really know why this is working:

And this is not:

Anyway, it is working like this:

Thanks a lot! :slight_smile:

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