Data Consolidation and Array Transformation using Function Node - n8n Workflow

Learn how to use an n8n node Function to consolidate multiple incoming items into a single JavaScript array. Essential n8n workflow technique for data transformation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

n8n Nodes Used

Who is this best for?


  • n8n users who need to restructure and consolidate split data payloads.

  • Developers requiring custom JavaScript transformation logic within an n8n workflow.

  • Automation specialists working with APIs that demand a single unified JSON array as input.

  • Those learning advanced data manipulation techniques in n8n templates.

Overview

Data transformation is a core requirement for robust automation. While many n8n nodes generate individual output items (splitting the data), subsequent services often require a single, unified array containing all records. This powerful n8n workflow addresses this challenge by providing a reusable n8n node configuration that merges multiple items into one comprehensive JSON array.

This specific n8n template uses the Function n8n node to map the input items, solving the common problem of item consolidation efficiently and reliably, making your overall n8n workflow cleaner and faster.

How it Works

This foundational n8n workflow begins without an external n8n trigger, relying instead on internal testing nodes to demonstrate the data flow.


  1. Data Simulation: The 'Mock Data' n8n node generates three separate input items, simulating data received from a previous step (like a database query or API call).

  2. Consolidation Logic: All three items flow into the 'Create an array of objects' n8n node. This Function n8n node executes custom JavaScript to iterate over the input array (items).

  3. Transformation: The script uses items.map(item => item.json) to extract the raw payload from each individual n8n item and compile it into one cohesive JavaScript array.

  4. Final Output: The n8n workflow concludes by outputting a single item containing the newly formed array under the key data_object. This technique ensures subsequent n8n nodes receive consolidated data, ready for bulk processing.

Installation Guide

To start using this data consolidation n8n workflow:


  1. Import the n8n Workflow: Copy the provided JSON code.

  2. Open your n8n instance and navigate to the 'Workflows' section.

  3. Click 'New' and select 'Import from JSON'. Paste the entire code.

  4. Execution: Since this n8n template uses only Function nodes, no external credentials are required. Simply click 'Test Workflow' or activate the workflow and execute it manually to see the data transformation in action.

  5. Review the output of the final n8n node to see the consolidated array structure.

Node Details

This n8n workflow utilizes two key Function n8n nodes:

Node Name: Mock Data (Function)
Function: Simulates the input data for the n8n workflow by generating three distinct n8n items, each containing a simple object (id and name).
Key Configuration: Contains hardcoded JavaScript returning an array of three separate objects to mimic the structure often seen after a Split In Batches or Database n8n node.

Node Name: Create an array of objects (Function)
Function: This critical n8n node performs the data consolidation, merging the separate incoming items into a single array structure.
Key Configuration: The JavaScript code used is return [ { json: { dataobject: items.map(item => item.json), }, } ];. This code maps over the input items, extracts the payload (item.json), and wraps the resulting JavaScript array into a single output item under the dataobject key. This demonstrates essential data manipulation techniques for any complex n8n template.

Related n8n Workflows

Free

Nodes: 1 Nodes
Updated: December 26 2025
View all
Created by
ghagrawal17
ghagrawal17

Featured*