Learn › n8n Foundations: From Zero to First Automation › Transforming Data: Edit Fields, Code Node, and Merge

Transforming Data: Edit Fields, Code Node, and Merge

Beginner 🕐 13 min Lesson 11 of 15
What you'll learn
  • Use the Edit Fields node to add, rename, and transform item fields with expressions
  • Write JavaScript in the Code node for complex transformations that expressions cannot handle
  • Combine data from two workflow branches using the Merge node's join modes

Data Rarely Arrives in the Right Shape

A webhook gives you a field named "first_name" but your CRM expects "firstName". An API returns prices in cents but you need them in pounds. One workflow branch produces an enriched record and another branch produces a sentiment score — and you need to combine both. Data transformation is the connective tissue of automation, and n8n gives you three tools for it.

Edit Fields (Set) Node

The Edit Fields node (also called the Set node) adds, renames, removes, or transforms fields on your items. It is the right tool for most transformation tasks that do not require complex logic.

In its settings panel you choose one of two modes:

  • Manual Mapping — Add each field you want on the output. Set its name, type (string, number, boolean, array, object), and value (fixed or expression). Items from the previous node are replaced by only the fields you define — so if you want to keep existing fields, use "Keep Only Set" option carefully.
  • JSON — Write the full output item as a JSON object directly. Good when you need to restructure deeply nested data.

Common uses: rename fields to match an API's expected format, add a calculated field ({{ $json.price * 1.2 }} for a 20% markup), remove sensitive fields before logging, or set a status field based on a condition.

Code Node

When transformations are too complex for expressions, the Code node lets you write real JavaScript (or Python on self-hosted instances) that runs as a workflow step. You have access to all items from the previous node via the items variable.

A basic Code node that uppercases a field:

return items.map(item => ({
json: { ...item.json, name: item.json.name.toUpperCase() }
}));

The Code node can install npm packages (self-hosted) or use the built-in ones (n8n Cloud). You can perform multi-step calculations, call other n8n functions, or restructure data in ways that would take dozens of Expression calls. If you are comfortable with JavaScript, the Code node removes nearly all limits on what you can do with data in n8n.

Merge Node

The Merge node takes inputs from two branches and combines them. It has several merge modes:

  • Combine by Position — pairs items from both inputs by index (item 1 from branch A + item 1 from branch B)
  • Combine by Field — joins items where a shared field value matches (like a SQL JOIN on a key)
  • Append — concatenates both lists into one longer list
  • Choose Branch — passes through whichever branch has data (useful for IF node reunification)

A typical Merge use case: one branch enriches a contact with company data from an API; another branch runs sentiment analysis on their last support ticket. Merge by Field (on email address) reunites both enriched records into one item before writing to the CRM.

Key takeaways
  • Edit Fields is the right tool for most transformations — rename fields, add calculated values, restructure data visually without writing code
  • The Code node runs real JavaScript (or Python on self-hosted) — use it when you need loops, complex conditionals, or data restructuring beyond what expressions support
  • Merge node combines two branches using position, field-based join, append, or branch-selection modes — 'Combine by Field' works like a SQL JOIN on a shared key