Aggregate Items into One Object

Difficulty
2/10
Tags
EssentialsHTTP RequestEdit Fields (Set)aggregateExpressionsJSONArrays

You're a headhunter. You've translated Chewbacca's CV from Wookiee growls to English, but the translations are scattered across 6 separate items. Time to reconstruct them into a proper CV object.

This challenge teaches you how to aggregate multiple items back into a single structured object.

What you'll practice:

  • Using the Aggregate node to combine multiple items
  • Accessing aggregated data with array indices
  • Rebuilding structured objects from collected data

Your Task

  1. 1Copy the exercise below
  2. 2Paste into your n8n editor (Ctrl+V)
  3. 3Solve it — use hints if you get stuck
  4. 4Check the solution when done

You have 6 translated items. Use the Aggregate node to collect them, then rebuild the CV object.

Your task:

  1. Add an Aggregate node after Combine Results
    • Set "Aggregate" to "All Item Data"
  2. Add an Edit Fields node to extract each translation by index:
    • name: {{ $json.data[0].translation }}
    • species: {{ $json.data[1].translation }}
    • homeworld: {{ $json.data[2].translation }}
    • age: {{ $json.data[3].translation }}
    • role: {{ $json.data[4].translation }}
    • employer: {{ $json.data[5].translation }}

Expected output:

{
  "name": "Chewbacca",
  "species": "Wookiee",
  "homeworld": "Kashyyyk",
  "age": "234 years",
  "role": "Co-Pilot",
  "employer": "Millennium Falcon"
}

Get the exercise workflow

Create a free account to copy exercises into your n8n editor.

Hints

  1. Add an Aggregate node after Combine Results
  2. In the Aggregate settings, set "Aggregate" to "All Item Data"
  3. Add an Edit Fields node after Aggregate
  4. Create 6 string fields, each accessing the translation by index:
    • name: {{ $json.data[0].translation }}
    • species: {{ $json.data[1].translation }}
    • homeworld: {{ $json.data[2].translation }}
    • age: {{ $json.data[3].translation }}
    • role: {{ $json.data[4].translation }}
    • employer: {{ $json.data[5].translation }}

Explanation

What is the Aggregate node?

The Aggregate node collects multiple items into a single item. When you set it to "All Item Data", it creates an array called data containing all the items that flowed into it.

The workflow flow:

Combine Results (6 items)
     ↓
Aggregate (1 item with data array)
     ↓
Edit Fields (extract translations)
     ↓
1 CV object

Understanding the aggregated data:

After the Aggregate node, your data looks like:

{
  "data": [
    {"field": "name", "value": "RAAAAWRGWAWGGR", "translation": "Chewbacca"},
    {"field": "species", "value": "WWWRRRAAAGH", "translation": "Wookiee"},
    ...
  ]
}

Accessing by index:

The expression $json.data[0].translation accesses:

  • $json - the current item's data
  • .data - the array of collected items
  • [0] - the first item (index 0 = name)
  • .translation - the translated value

The result:

You now have Chewbacca's CV translated into readable English! The final step is to format this into a recommendation email.

Copy the Solution

Paste into n8n with Ctrl+V to compare with your approach.

How was this lesson?

Get the solution workflow

Create a free account to copy solutions into your n8n editor.

Related Content

Continue your learning journey with these related lessons and guides: