Data Transformation
Map, filter, aggregate, and reshape data as it flows through your automation pipeline.
Data Transformation in Workflows
Most real-world automation workflows spend more time transforming data than executing business logic. Understanding transformation patterns prevents brittle workflows that break on minor format changes.
n8n's Transformation Nodes
Set node — add, modify, or remove fields from each item.
Function node (Code) — write JavaScript to transform data arbitrarily.
Merge node — combine data from multiple branches.
Split In Batches — process large arrays in chunks.
Filter node — remove items that don't match criteria.
Common Transformations
Field mapping (renaming and restructuring):
// Transform CRM format to email format
return items.map(item => ({
json: {
to: item.json.email_address,
name: `${item.json.first_name} ${item.json.last_name}`,
company: item.json.organization_name
}
}));
Aggregation (combining many items into one):
const summary = items.reduce((acc, item) => ({
total: acc.total + item.json.amount,
count: acc.count + 1
}), { total: 0, count: 0 });
return [{ json: summary }];
Schema Validation Mid-Pipeline
Validate data shape between workflow stages. A malformed item that passes through 5 nodes before failing is much harder to debug than one that fails immediately.
Add validation nodes at entry points and after external API calls.
The Transformation Testing Problem
Transformations fail on edge cases: null values, empty arrays, unexpected types. Write transformation logic defensively — assume any field can be missing or malformed. Test with representative samples including edge cases before deploying.