Complete "Lesson 1: How n8n Structures Data — Items, JSON, and the Execution Model" first to unlock this lesson.Go to previous lesson

Introduction

The Set node is your primary tool for reshaping data as it flows through n8n workflows. Unlike nodes that fetch external data, Set focuses entirely on transforming what you already have: adding new fields, overwriting existing ones, or removing fields you don't need. This makes it essential for preparing payloads before sending them to APIs, databases, or other services.

Every item in n8n is a JSON object. The Set node lets you define exactly which fields each item should contain and what values they should hold. You can hardcode values, copy data from other fields, or use expressions to calculate new values based on upstream data.

Basic Field Operations

The Set node operates in one of two modes: Keep Only Set (replaces the entire item with only the fields you define) or Add/Overwrite (merges your new fields into the existing item). For most transformation tasks, Add/Overwrite gives you more flexibility.

To add a field, click Add Field and choose the appropriate type: String, Number, Boolean, or others. Each field requires a name and a value. The name becomes the JSON key, and the value can be static text, a number, or an expression.

javascript
// Example: Transforming API response items
// Input item from HTTP Request node:
{
"user_id": 42,
"full_name": "Alice Smith",
"created_at": "2024-01-15T10:30:00Z"
}
// Set node configuration (Add/Overwrite mode):
// Field 1: id (Number) = {{$json.user_id}}
// Field 2: name (String) = {{$json.full_name}}
// Field 3: isActive (Boolean) = true
// Output item:
{
"user_id": 42,
"full_name": "Alice Smith",
"created_at": "2024-01-15T10:30:00Z",
"id": 42,
"name": "Alice Smith",
"isActive": true
}

Notice that the original fields remain. If you switch to Keep Only Set mode, the output would contain only id, name, and isActive.

flowchart showing Add/Overwrite mode merging new fields into existing item versus Keep Only Set mode replacing entire item

Referencing Upstream Data with Expressions

Expressions are how you access data from previous nodes. The most common pattern is {{$json.fieldName}}, which reads a field from the current item. You can also use JavaScript inside expressions to transform values on the fly.

javascript
// Input item:
{
"email": "alice@example.com",
"score": 85
}
// Set node fields using expressions:
// Field 1: username (String) = {{$json.email.split('@')[0]}}
// Field 2: domain (String) = {{$json.email.split('@')[1]}}
// Field 3: passed (Boolean) = {{$json.score >= 70}}
// Field 4: grade (String) = {{$json.score >= 90 ? 'A' : $json.score >= 70 ? 'B' : 'C'}}
// Output item:
{
"email": "alice@example.com",
"score": 85,
"username": "alice",
"domain": "example.com",
"passed": true,
"grade": "B"
}

You can reference fields from other nodes using {{$node.NodeName.json.fieldName}}. This is useful when you need to combine data from multiple sources or compare values across workflow steps.

javascript
// Example: Combining data from two nodes
// Webhook node output: {"orderId": "ORD-123"}
// HTTP Request node output: {"status": "shipped", "trackingCode": "TRK-456"}
// Set node fields:
// Field 1: order (String) = {{$node.Webhook.json.orderId}}
// Field 2: status (String) = {{$json.status}}
// Field 3: tracking (String) = {{$json.trackingCode}}
// Output:
{
"order": "ORD-123",
"status": "shipped",
"tracking": "TRK-456"
}

Removing Unwanted Fields

Sometimes you need to strip out sensitive or unnecessary fields before sending data downstream. In Keep Only Set mode, you simply define the fields you want to keep and everything else disappears. In Add/Overwrite mode, removing fields requires using the Remove Other Fields toggle or manually setting fields to null.

javascript
// Input item with sensitive data:
{
"userId": 42,
"email": "alice@example.com",
"password_hash": "$2b$10$abcd...",
"internal_notes": "VIP customer",
"created_at": "2024-01-15T10:30:00Z"
}
// Set node in Keep Only Set mode:
// Field 1: userId (Number) = {{$json.userId}}
// Field 2: email (String) = {{$json.email}}
// Output (password and notes removed):
{
"userId": 42,
"email": "alice@example.com"
}

This approach is safer than trying to delete fields individually, especially when dealing with dynamic data structures where you might not know all field names in advance.

Common Patterns and Gotchas

When building complex transformations, work incrementally. Add one or two fields, execute the node, and verify the output before adding more. This makes debugging much easier than configuring ten fields at once and troubleshooting errors.

Expression errors are common. If an expression fails to evaluate, n8n usually leaves the field empty or shows an error badge. Double-check your syntax: expressions must be wrapped in double curly braces, and JavaScript code inside must be valid. Use the Expression Editor panel to test expressions before committing them.

Type mismatches can cause downstream issues. If a field expects a number but receives a string, explicitly convert it using Number or parseInt inside your expression. Similarly, use String to convert numbers to text when needed.

javascript
// Type conversion examples:
// Field 1: age (Number) = {{Number($json.age_string)}}
// Field 2: id (String) = {{String($json.numeric_id)}}
// Field 3: price (Number) = {{parseFloat($json.price_with_currency.replace('$', ''))}}

The Set node processes each item independently. If you have 50 items entering the node, each one gets transformed according to your field definitions. This means expressions like {{$json.fieldName}} always refer to the current item being processed, not the entire array.

Summary

The Set node is your scalpel for data transformation in n8n. Use Add/Overwrite mode when you want to augment existing data, and Keep Only Set when you need to create a clean slate with only specific fields. Expressions let you reference data from anywhere in your workflow and apply JavaScript transformations inline. Master the Set node and you'll spend less time wrestling with data formats and more time building functional workflows.

Lesson practice

Lesson Checkpoint

Review what you learned and get feedback on your work.

0/1
Answered · 0/1