How to Handle Data Transformation in n8n: Set, Edit Fields & Code Node Explained (2025)

Most n8n workflows don't break at the API call — they break at the data between nodes. One tool returns a shape the next tool won't accept, and everything stops. Learning to reshape data cleanly is the skill that separates fragile workflows from bulletproof ones. Here's how.

The Edit Fields (Set) node

Your everyday workhorse. Use Edit Fields to add, rename, or drop fields and map messy input into a clean, predictable object. Set it to "Keep Only Set Fields" when you want to strip a bloated API response down to just what the next node needs.

Expressions: the glue

Anywhere you see the expression editor, you can reach into prior data with {{ $json.fieldName }}, reference other nodes with {{ $('Node Name').item.json.x }}, and use built-in functions to format dates, split strings, and do math. Expressions handle 80% of transformations without a line of real code.

When to reach for the Code node

For anything expressions can't express — complex loops, custom parsing, merging arrays — use the Code node (JavaScript or Python). Run it "once for all items" to transform the whole batch, or "once per item" for row-by-row logic. Return an array of { json: {...} } objects and n8n picks up from there.

Skip the transformations — just ask in plain English

This Text-to-SQL template lets you query your database with natural language and get structured results. No expressions, no code node.

Get the template on Gumroad →

Items, not variables

The mental model that fixes most confusion: n8n passes items (an array of JSON objects) between nodes, not single values. A node runs once per item by default. Understand that and "why did my node run 50 times?" answers itself.

Splitting and aggregating

Use Split Out to turn one item with an array into many items, and Aggregate to collapse many items back into one. These two nodes solve the majority of "I need to loop over a list" problems without any code.

Conclusion

Master Edit Fields, expressions, and the items model, and you'll spend far less time debugging and far more time shipping. The Code node is there for the last 10% — but you'll need it less than you think.

Ready to automate this in minutes?

Skip the build. Import a battle-tested n8n workflow, connect your credentials, and go live today.

Get this template on Gumroad →