API returns array. How to turn that into elements and then process them into a list?

With HTTP Request I call an API that returns an array of objects.

Each object has a property with another array.

Like this:

# Api response:
[
    {
        "name": "Alice",
        "places":
        [
            { "city": "Barcelona", "language": "Catalan" },
            { "city": "London", "language": "English" },
        ]
    },
    {
        "name": "Bob",
        "places":
        [
            { "city": "Paris", "language": "French" },
            { "city": "Bangkok", "language": "Thai" },
        ]
    }
]

The node wraps that inside a [] to turn the response into the 1st element of the “array of items to send to the next node”:

# Node response
[
    [
        {
            "name": "Alice",
            "places":
            [
                { "city": "Barcelona", "language": "Catalan" },
                { "city": "London", "language": "English" },
            ]
        },
        {
            "name": "Bob",
            "places":
            [
                { "city": "Paris", "language": "French" },
                { "city": "Bangkok", "language": "Thai" },
            ]
        }
    ]
]

I want to make a list of all the cities in excel like this:

name    city        language
Alice   Barcelona   Catalan
Alice   London      English
Bob     Paris       French
Bob     Bangkok     Thai

I already know how to make the API call and how to write excels.

How do I do the intermediate processing?

Hi @xmontero, you can customize this behaviour by enabling the Split Into Items option of the HTTP Request node:

image

When enabled, the n8n data structure should look like your API response. You can then use the Item Lists node and the Set (or Rename Keys) node to format the data, for example like so:

Result:

1 Like