Key Concepts of n8n – Part 4: n8n Data Transformation Nodes Explained

Table of Contents
- 💡 Why n8n Data Transformation Matters
- ⚙️ Edit Fields (Set) Node: Your Data Shaper
- 🔗 Merge Node: Combining Data from Different Sources
- ↕️ Sort Node: Organizing Data in Your Workflow
- 💻 Code Node: The Modern Power Tool for Custom Logic
- 🌍 Real-World Use Cases
- 🎯 Best Practices & Common Mistakes
- 🏁 Wrapping Up
In the previous parts of our n8n Key Concepts series— Part 1,Part 2,and Part 3 —we explored how workflows start, how nodes work, and the different types of trigger nodes. Now it’s time to tackle one of the most useful concepts in building real-world workflows: data transformation.
Data doesn’t always come in the perfect format. Sometimes, an API gives you too much information. Other times, form submissions are messy or need tweaking. That’s where n8n data transformation nodes like Set, Merge, and Function or Code come in.
Let’s break them down, look at when to use each, and explore some common use cases.
💡 Why n8n Data Transformation Matters
Think of data transformation as the “middle step” that makes raw input usable. You might start with a webhook that collects 10 fields, but only 3 of those are relevant for your database. Or maybe you fetch product prices from an API and need to calculate tax before displaying them.
Example: You’re pulling data from an API and it returns this:
{
"user_email": "jane@example.com",
"full_name": "Jane Doe",
"location": "NYC"
}
But you just need:
{
"email": "jane@example.com",
"name": "Jane Doe"
}
That’s a perfect use case for a Set Node.
⚙️ Edit Fields (Set) Node: Your Data Shaper
The Set node, now officially called the Edit Fields (Set) node, is one of the most fundamental and frequently used tools in n8n. It allows you to precisely control the data that flows through your workflow. You can perform several key operations:
- Set new values: Create new fields with static values or dynamic ones using expressions.
- Modify existing values: Overwrite the data in fields that already exist.
- Rename fields: Change the name (key) of a field to match what the next node expects.
- Filter fields: By default, the node passes all incoming data through. But by disabling the “Include Other Input Fields” option, you can choose to *only* output the fields you’ve defined, effectively filtering out everything else.

Use case: Imagine a webhook receives data like this:
{
"form_id": 123,
"fname": "John",
"lname": "Doe",
"email_address": "john@example.com",
"unused_field": "xyz"
}
You want to clean this up before sending it to your CRM. You can use a single Edit Fields node to:
- Rename
email_addresstoemail. - Create a new
fullNamefield by combiningfnameandlnamewith an expression. - Add a static
sourcefield. - Filter out the unneeded
form_idandunused_field.
This single node transforms the messy input into a clean, ready-to-use output, making your data perfect for the next step.
🔗 Merge Node: Combining Data from Different Sources
Sometimes, one node doesn’t give you all the info you need. Maybe your CRM provides customer data, and your order system has their purchases. You want both. That’s where the Merge node comes in.
The Merge Node in n8n allows you to combine data coming from two inputs — but how it merges that data depends entirely on the mode you select. This makes it a flexible yet sometimes tricky node to use effectively.

Merge Modes
| Mode | Description |
|---|---|
| Append | Combines both input item arrays into one list. Items from Input 1 appear first, followed by items from Input 2 — no merging happens at the object level. ✔️ Use this when you want to combine two lists (e.g., two search results). |
| Merge by Index | Combines items at the same position from each input by merging their properties. Index 0 from Input 1 + Index 0 from Input 2 → one merged item. ⚠️ Pitfall: Only as many items are returned as the shorter input. |
| Merge by Key | Combines items based on a matching key in both inputs (e.g., id, email). Keys must exist in both inputs, or they won’t be merged. The node checks for matches and merges properties together when matched. |
🧪 Example: Merge by Key
Let’s say:
Input 1 (Customers):
[
{ "id": 101, "name": "Alice" },
{ "id": 102, "name": "Bob" }
]
Input 2 (Orders):
[
{ "id": 101, "order_total": 150 },
{ "id": 103, "order_total": 90 }
]
Using Merge by Key on id, the output will be:
[
{ "id": 101, "name": "Alice", "order_total": 150 }
]
Only items with matching keys are merged. Item id: 102 from Input 1 and id: 103 from Input 2 are discarded because they don’t have matches in the other input.
💡 Pro Tips
- ✅ Always ensure your key fields exist in both inputs.
- 🧪 For lists of different lengths, test with sample data and observe how index-based merging behaves.
- 🔧 Use a
Set Nodebefore Merge if you need to normalize or rename key fields (e.g., aligningcustomer_idtoid). - 🔄 To retain all items regardless of key match, consider restructuring with a
FunctionorCode Nodeinstead.
↕️ Sort Node: Organizing Data in Your Workflow
The Sort Node is a helpful tool when you’re working with lists of data that need to be ordered in a particular way — whether that’s alphabetically, by value, or by timestamp.
It’s especially useful when you want to clean and organize results before performing additional logic, like sending reports, ranking items, or even feeding the data into an AI agent.

How the Sort Node Works
You tell the Sort Node which field to sort by and whether you want it in ascending (A–Z, 0–9) or descending (Z–A, 9–0) order. It takes an array of items and rearranges them based on your rule.
When to Use the Sort Node
- Sort lists by name, value, or timestamp
- Rank entries from highest to lowest (e.g., top 5 products)
- Prepare data before passing it into If or Code nodes that expect a certain order
Example: Sort Orders by Date
Say you’ve collected a bunch of customer orders and want to process the most recent ones first.
Sort Node settings:
- Field:
orderDate - Order: Descending
Sorted output:
[
{ "orderId": 3, "orderDate": "2024-05-10" },
{ "orderId": 2, "orderDate": "2024-04-27" },
{ "orderId": 1, "orderDate": "2024-03-14" }
]
💡 Pro Tip: You can use the Sort Node right after a Merge or API call to tidy up incoming results before making conditional decisions.
💻 Code Node: The Modern Power Tool for Custom Logic
The Code node is a powerful and flexible node in n8n that allows you to write your own JavaScript (or Python) code to process and transform data. It replaces both the legacy Function and Function Item nodes starting from n8n version 0.198.0.
You can use the Code node to:
- Perform advanced data transformations
- Calculate or reformat values
- Filter or restructure data
- Work with multiple inputs and outputs
- Handle conditional logic within custom scripts

The Code node supports two execution modes:
- Run Once for Each Item: processes one item at a time (similar to the old Function node)
- Run Once for All Items: gives you access to the whole array of inputs, useful for aggregation, filtering, or restructuring
Example: Add 20% tax to a product price
const price = $json.price;
return [
{
json: {
priceWithTax: price * 1.2
}
}
];
💡 Tip: The Code node is the go-to choice for most custom logic tasks in modern n8n workflows. It is especially useful when dealing with multiple data sources or needing full control over how data is processed.
⚠️ Version Compatibility Notice
If you’re using an older version of n8n (before v0.198.0), you won’t have access to the Code node. In that case, you should continue using:
Function NodeFunction Item Node
These nodes are still functional in older builds but are considered legacy and no longer recommended for new workflows.
🌍 Real-World Use Cases
Here are a few scenarios where transformation nodes really shine:
- Cleaning form data before saving to Airtable
- Merging CRM info with order history for customer segmentation
- Standardizing names (capitalize first letter) before emailing
- Converting timestamps to user’s local time zone
- Filtering out incomplete data before sending to API
A typical pattern might look like this:
Webhook -> Set Node -> Merge Node -> Code Node -> Output
🎯 Best Practices & Common Mistakes
Best Practices:
- Keep logic modular. Don’t do too much in one Code Node.
- Always comment your code for clarity and future reference.
- Test each step with mock data using the node’s built-in preview.
Pitfalls to Avoid:
- Trying to merge by a key that doesn’t exist.
- Forgetting that Edit Fields (Set) Node overwrites your entire JSON unless you disable “Include Other Input Fields”.
- Overusing Function Node when a Set Node would suffice.
- Returning incorrect format in Code Node (should be
[ { json: {...} } ]).
🏁 Wrapping Up
Part 5 – Logic & Flow Control Nodes, where we explore If, Switch, and more.
Want to see a full example in action? Browse our verified templates on the workflow page or download the JSON to test it out in your own n8n instance.