Data transformation is where n8n workflows are actually built or broken, and where newcomers struggle — not because it is hard, but because n8n's item-based model is unfamiliar. Understand how items flow, and choosing the right transformation tool becomes obvious.
The item model
Data moves between n8n nodes as an array of items, each a JSON object. A node runs once per incoming item by default, and outputs items to the next node. Almost every "why is this looping" or "why do I only get one result" confusion is a mismatch between how many items you think you have and how many you actually do. Watch the item count on each node — it is the single most useful debugging habit in n8n.
Set, expression, or Code
| Need | Use |
|---|---|
| Rename, add, or drop a few fields | Set node |
| Compute one value inline | An expression on a field |
| Reshape arrays, merge, complex logic | Code node (JavaScript) |
| Custom per-item mapping at scale | Code node, run-once-per-item mode |
Reach for the Set node for straightforward field mapping — it is declarative and readable. Use expressions ({{ }}) for quick inline computation drawing on data from earlier nodes. Drop to the Code node only when the logic genuinely needs it: reshaping nested arrays, aggregating across items, anything a Set node would turn into a tangle.
// Flatten Acumatica line items into one item per line
const out = [];
for (const item of $input.all()) {
for (const line of item.json.Details) {
out.push({ json: {
order: item.json.OrderNbr.value,
sku: line.InventoryID.value,
qty: line.Quantity.value,
}});
}
}
return out;
Arrays and nested data
ERP and API payloads are deeply nested, and this is where the Code node earns its place. Use it to flatten nested arrays into flat items, or the Item Lists node to split an array field into individual items. The rule of thumb: get the data into the shape where one item equals one thing you want to act on, as early as possible, and the rest of the workflow becomes simple.
n8n lets you pin the output of a node so you can iterate on downstream transformations without re-calling the source API every time. Pin a real sample response and build your mapping against it — faster, deterministic, and it saves you from burning API quota while you experiment.
Transformation in n8n is a small toolkit used well: know the item model, prefer the Set node and expressions for simple shaping, drop to the Code node for real reshaping, and flatten to one-item-per-thing early. Pin sample data while you build, and the transformations stop fighting you.
Independent software engineer in Nairobi specialising in Acumatica customisations, Laravel backends, and tax fiscalisation integrations across East and Southern Africa.