Working with JSON data is central to mastering workflow automation in n8n. Whether you're combining data from multiple APIs, merging two webhook responses, or joining internal datasets, knowing how to merge two JSON objects in n8n is a must-have skill. The best part? You can do it cleanly and efficiently with built-in nodes—no coding required.
Let’s walk through why and how to merge JSON objects like a pro inside n8n, with practical steps and examples to help you along the way.
Why Merge JSON Objects in n8n?
Before jumping into the how-to, let’s address the why. Merging JSON objects is essential when you want to:
- Combine data from multiple nodes into one unified structure
- Send consolidated data to a downstream system (e.g., a database, CRM, or HTTP endpoint)
- Perform logic operations based on merged information
- Save API calls by combining responses
For example, imagine you have one API returning customer details and another returning the customer’s order history. Instead of handling two separate outputs, you can merge them and work with a single unified object.
Understanding JSON Objects in n8n
In n8n, every node typically outputs data in the following structure:
[
{
"json": {
"key1": "value1",
"key2": "value2"
}
}
]
So when we talk about merging multiple JSON objects, we’re referring to combining the contents of multiple json payloads into one.
Let’s cover the step-by-step approach to achieve just that.
Method 1: Use the ‘Merge’ Node
The most straightforward approach in n8n is to use the built-in Merge node.
Step-by-Step: How to Merge Two JSON Objects in n8n Using the Merge Node
1. Start Your Workflow
Begin with any two nodes that produce JSON output you want to merge. For example:
- An HTTP Request node fetching user profile data
- Another HTTP Request node fetching the user’s activity logs
2. Add a Merge Node
Drag the Merge node into your canvas. This node has two inputs—Input 1 and Input 2.
3. Choose Merge Mode
Click the Merge node and select the mode “Merge By Index”.
This mode takes the first JSON item from each input and merges them together.
Here’s a basic visual of how it works:
| Input 1 JSON | Input 2 JSON | Merged Output |
|---|---|---|
{ "name": "Alice" } |
{ "age": 28 } |
{ "name": "Alice", "age": 28 } |
4. Connect the Inputs
Connect your two data source nodes to the respective inputs of the Merge node.
Tip: The “left” input is Input 1, and the “top” input is Input 2.
5. Execute the Merge Node
Run the workflow. Your merged JSON object will appear in the Output of the Merge node.
Use the output like this in your next step, such as sending a POST request or saving results in Google Sheets.
When to Use ‘Merge by Index’ vs Other Modes
The Merge node supports different strategies:
- Merge By Index – Matches first item from each input (most common)
- Merge By Key – Merges items where a key (like
userId) matches - Pass-Through – Only passes one input while attaching the second as metadata
In most cases, for combining two JSON objects into one, “Merge By Index” works best.
Method 2: Use the ‘Set’ and ‘Function’ Nodes (For Advanced Needs)
If you want more control, such as handling nested objects or conditional logic, use a Function node.
Step-by-Step: Merge JSON in a Function Node
Let’s say you want to merge the data from Input A and Input B manually.
1. Output Both Objects to the Same Function Node
Make sure your previous nodes send data to a Function Node either as combined output or using incoming variables.
2. Write Merge Code
Inside the Function node, input this code:
const dataA = $items(0)[0].json;
const dataB = $items(1)[0].json;
return [{
json: {
...dataA,
...dataB
}
}];
This method uses JavaScript spread syntax to merge both objects cleanly.
When to Use This Method
Use the Function approach when:
- You have nested objects to merge
- You want to perform custom logic during merge
- Inputs come from different branches or need filtering
This method is especially useful when combined with more advanced custom nodes or third-party APIs.
Real-World Use Case: Merge Customer Info and Order Data
Here’s a practical example of merging two JSON objects using the Merge node:
- HTTP Node A: Fetch user information
Output:{ "id": 1, "name": "John Doe" } - HTTP Node B: Fetch most recent order
Output:{ "orderId": "A123", "status": "pending" }
Using a Merge Node (Merge by Index), your final object becomes:
{
"id": 1,
"name": "John Doe",
"orderId": "A123",
"status": "pending"
}
This object can now be sent to a Slack channel, stored in Airtable, or pushed to a CRM.
Common Pitfalls and How to Avoid Them
- Mismatched array lengths: If inputs have arrays of different sizes, “Merge by Index” may not behave as expected. Either pad shorter arrays or pre-process them.
- Missing inputs: If one of your nodes fails, the Merge node may fail too. Handle errors using error handling in n8n gracefully.
- Incorrect data types: Ensure both inputs are object-based. Merging arrays with objects won’t work as intended.
Pro Tips
- Use the Set node before the Merge to rename conflicting keys
- Combine “Merge Node” with IF or Switch nodes for dynamic merge logic
- Add custom community nodes if you want helper utilities for JSON transformations
FAQ
How to merge two JSON objects in n8n?
You can merge two JSON objects in n8n using the Merge node set to “Merge By Index.” You can also use a Function node for more complex merge operations using JavaScript.
Can I merge more than two JSON objects?
Yes. To merge more than two JSON objects, you can chain multiple Merge nodes or combine them in a Function node using the ... spread syntax.
What happens if both objects have the same keys?
When merging with the spread operator, values from the second object will overwrite the keys from the first. In the Merge node, it also prioritizes Input 2’s values in case of conflict.
Can I merge arrays inside JSON objects in n8n?
The Merge node doesn't deep merge arrays automatically. For that, you’ll need to use a Function node and write code to concatenate or merge arrays manually.
Is merging JSON in n8n better than using external APIs?
Yes, it saves time and increases reliability. Instead of sending partial data externally, you can handle most logic inside n8n efficiently, keeping workflows fast and secure.
By mastering how to merge two JSON objects in n8n, you'll unlock higher levels of automation and make your workflows more dynamic and efficient. Whether it's simple API integration or complex AI agent orchestration, understanding data merging is foundational to success in no-code automation.
Copy-paste templates.
Beginner friendly.