G: Are you tired of wrestling with inconsistent data formats, missing fields, or redundant information in your automation workflows? Do you spend too much time manually cleaning up data before it can be used by the next step in your process? If so, you’re in the right place!
n8n, the powerful workflow automation tool, offers a fantastic solution to these data woes: the Set Node. While seemingly simple, the Set Node is an absolute workhorse, acting as your personal data sculptor. It’s the unsung hero that ensures your data is perfectly shaped and ready for any challenge your workflow throws at it.
In this comprehensive guide, we’re diving deep into the n8n Set Node. We’ll explore its core capabilities and, most importantly, provide 10 practical, real-world examples that will empower you to handle even the most complex data transformations with ease. Get ready to turn data chaos into data clarity! 🚀
What is the n8n Set Node? 🤔
At its heart, the n8n Set Node allows you to add, modify, remove, or rename properties (fields) within your data items. Think of it as a highly flexible data editor that operates on the individual items flowing through your n8n workflow.
Why is it so essential?
- Data Consistency: Ensure all your data items have the necessary fields in the correct format.
- Data Cleaning: Remove sensitive, irrelevant, or redundant information.
- Data Enrichment: Add new, calculated, or static fields to your data.
- API Compatibility: Transform data from one system’s format into another’s.
- Workflow Readiness: Prepare data for subsequent nodes that expect specific structures.
The Set Node typically works with JSON data, which is the native format for items in n8n. You configure it by specifying keys (the field names) and values (the data for those fields).
The Power of Expressions ✨
The real magic of the Set Node comes alive when you combine it with expressions. Expressions in n8n allow you to dynamically generate values based on existing data, variables, or even complex logic. You’ll see them enclosed in double curly braces, like {{ $json.fieldName }}
.
$json.fieldName
: Refers to the value of a field in the current data item.$now
: Represents the current timestamp.$env.VARIABLE_NAME
: Accesses environment variables.- JavaScript operators (
+
,-
,*
,/
,==
,!=
,&&
,||
,? :
), string methods (.toUpperCase()
,.trim()
), and array methods (.map()
,.filter()
) can be used within expressions.
Let’s dive into the examples! For each example, we’ll provide a scenario, example input, how to configure the Set Node, and the expected output.
10 Practical n8n Set Node Examples You Need to Know!
Example 1: Adding a New Field with a Static Value 🆕
Scenario: You need to mark all incoming customer records with a default status, like “New Lead,” before further processing.
Input:
[
{
"name": "Alice Smith",
"email": "alice@example.com"
}
]
Set Node Configuration:
- Operation: Add
- Value: String
- Keep Only Set: No (You want to add to existing data)
- Values to Set:
- Key:
status
- Value:
New Lead
- Key:
Output:
[
{
"name": "Alice Smith",
"email": "alice@example.com",
"status": "New Lead"
}
]
Example 2: Adding a New Field with a Dynamic Value (Expressions) 🧩
Scenario: You receive separate firstName
and lastName
fields and need to create a fullName
field for easier display or integration with another system.
Input:
[
{
"firstName": "Bob",
"lastName": "Johnson",
"email": "bob@example.com"
}
]
Set Node Configuration:
- Operation: Add
- Value: Expression
- Keep Only Set: No
- Values to Set:
- Key:
fullName
- Value:
{{ $json.firstName + ' ' + $json.lastName }}
- Key:
Output:
[
{
"firstName": "Bob",
"lastName": "Johnson",
"email": "bob@example.com",
"fullName": "Bob Johnson"
}
]
Example 3: Renaming Existing Fields 🔄
Scenario: An API you’re consuming returns product_id
and item_price
, but the database you’re writing to expects productId
and price
.
Input:
[
{
"product_id": "ABC123",
"item_price": 99.99,
"description": "Gizmo"
}
]
Set Node Configuration:
- Operation: Rename
- Keep Only Set: No
- Values to Set:
- Current Name:
product_id
- New Name:
productId
- Current Name:
item_price
- New Name:
price
- Current Name:
Output:
[
{
"productId": "ABC123",
"price": 99.99,
"description": "Gizmo"
}
]
Example 4: Removing Unnecessary Fields 🧹
Scenario: Your incoming data contains sensitive or redundant fields like password_hash
or internal _debugId
that you don’t want to pass to subsequent systems or store.
Input:
[
{
"id": 1,
"username": "user123",
"email": "user@example.com",
"password_hash": "ksjdlfkjsdlkfjdsf",
"_debugId": "abc-xyz-123"
}
]
Set Node Configuration:
- Operation: Remove
- Keep Only Set: No
- Values to Set:
- Key:
password_hash
- Key:
_debugId
- Key:
Output:
[
{
"id": 1,
"username": "user123",
"email": "user@example.com"
}
]
Example 5: Conditional Logic for Field Values 🤔
Scenario: You want to assign a priority
status based on the amount
of a transaction. If the amount is over $1000, it’s “High” priority; otherwise, it’s “Normal.”
Input:
[
{
"transactionId": "TXN001",
"amount": 1500
},
{
"transactionId": "TXN002",
"amount": 500
}
]
Set Node Configuration:
- Operation: Add
- Value: Expression
- Keep Only Set: No
- Values to Set:
- Key:
priority
- Value:
{{ $json.amount > 1000 ? 'High' : 'Normal' }}
- Key:
Output:
[
{
"transactionId": "TXN001",
"amount": 1500,
"priority": "High"
},
{
"transactionId": "TXN002",
"amount": 500,
"priority": "Normal"
}
]
Example 6: Type Conversion (String to Number/Boolean) 💡
Scenario: Data from a CSV or a legacy system often comes in as strings, even if they represent numbers or booleans. You need to convert them to their proper data types for calculations or strict API requirements.
Input:
[
{
"productPrice": "123.45",
"isActive": "true",
"quantity": "5"
}
]
Set Node Configuration:
- Operation: Add (or Set, if overwriting existing)
- Keep Only Set: No
- Values to Set:
- Key:
productPrice
- Value:
{{ parseFloat($json.productPrice) }}
- Value Type: Number (n8n usually infers, but good to be explicit for clarity)
- Key:
isActive
- Value:
{{ $json.isActive === 'true' }}
- Value Type: Boolean
- Key:
quantity
- Value:
{{ parseInt($json.quantity) }}
- Value Type: Number
- Key:
Output:
[
{
"productPrice": 123.45,
"isActive": true,
"quantity": 5
}
]
Example 7: Creating and Populating Nested Objects 📦
Scenario: You receive address components (street, city, zip) as flat fields, but the target system expects a nested address
object.
Input:
[
{
"orderId": "ORD456",
"customerName": "Jane Doe",
"street": "123 Main St",
"city": "Anytown",
"zipCode": "12345"
}
]
Set Node Configuration:
- Operation: Add
- Value: JSON
- Keep Only Set: No
- Values to Set:
- Key:
shippingAddress
- Value:
{ "street": "{{ $json.street }}", "city": "{{ $json.city }}", "zipCode": "{{ $json.zipCode }}" }
- Key:
Output:
[
{
"orderId": "ORD456",
"customerName": "Jane Doe",
"street": "123 Main St",
"city": "Anytown",
"zipCode": "12345",
"shippingAddress": {
"street": "123 Main St",
"city": "Anytown",
"zipCode": "12345"
}
}
]
Tip: After creating the nested object, you might use another Set Node (Operation: Remove) to delete the original flat street
, city
, and zipCode
fields if they are no longer needed.
Example 8: Modifying/Adding Elements to an Array 🏷️
Scenario: You have a list of tags for a product, and you want to ensure a specific tag (“Processed”) is always present, or add a new tag based on some condition.
Input:
[
{
"productId": "P001",
"tags": ["Electronics", "Gadgets"]
},
{
"productId": "P002",
"tags": ["Books"]
},
{
"productId": "P003"
}
]
Set Node Configuration:
- Operation: Add
- Value: Expression
- Keep Only Set: No
- Values to Set:
- Key:
tags
- Value:
{{ $json.tags ? $json.tags.concat('Processed') : ['Processed'] }}
- Key:
Output:
[
{
"productId": "P001",
"tags": ["Electronics", "Gadgets", "Processed"]
},
{
"productId": "P002",
"tags": ["Books", "Processed"]
},
{
"productId": "P003",
"tags": ["Processed"]
}
]
Explanation: This expression checks if tags
already exists. If it does, it concatenates the new tag. If not, it creates a new array with just the “Processed” tag.
Example 9: Formatting Dates and Timestamps ⏰
Scenario: You need to add a processedAt
timestamp to each item, formatted in a specific way (e.g., YYYY-MM-DD HH:mm:ss) for logging or database insertion.
Input:
[
{
"recordId": "R001",
"data": "some value"
}
]
Set Node Configuration:
- Operation: Add
- Value: Expression
- Keep Only Set: No
- Values to Set:
- Key:
processedAt
- Value:
{{ formatDate($now, "YYYY-MM-DD HH:mm:ss") }}
- Key:
Output:
[
{
"recordId": "R001",
"data": "some value",
"processedAt": "2023-10-27 10:30:00" // (Actual date/time will vary)
}
]
Note: formatDate
is a powerful n8n function based on luxon
(or moment
in older versions). You can find many formatting options in the n8n documentation.
Example 10: Setting Fallback Values for Missing Data 🛡️
Scenario: You have a userName
field, but sometimes it’s missing. If userName
is absent, you want to use email
as a fallback. If both are missing, use “Guest”. This is crucial for display purposes or ensuring a non-empty field.
Input:
[
{
"id": 1,
"userName": "john.doe",
"email": "john@example.com"
},
{
"id": 2,
"email": "jane@example.com"
},
{
"id": 3,
"source": "anonymous"
}
]
Set Node Configuration:
- Operation: Add
- Value: Expression
- Keep Only Set: No
- Values to Set:
- Key:
displayName
- Value:
{{ $json.userName || $json.email || 'Guest' }}
- Key:
Output:
[
{
"id": 1,
"userName": "john.doe",
"email": "john@example.com",
"displayName": "john.doe"
},
{
"id": 2,
"email": "jane@example.com",
"displayName": "jane@example.com"
},
{
"id": 3,
"source": "anonymous",
"displayName": "Guest"
}
]
Explanation: The ||
(OR) operator in JavaScript (and n8n expressions) works as a “first truthy value” selector. It checks userName
, if it exists and is not empty/null, it uses that. Otherwise, it checks email
. If both are “falsy”, it defaults to “Guest”.
Best Practices for Using the Set Node ✅
- Understand “Keep Only Set” vs. “Add”:
- Add: Appends the new/modified fields to the existing data. This is the default and most common.
- Keep Only Set: Discards all original fields and only outputs the fields you’ve explicitly defined in the Set Node. Use this for “projecting” or selecting only specific fields.
- Order Matters (Sometimes): If you’re using a field you just created in the same Set Node for another calculation, ensure the creation comes first in the “Values to Set” list.
- Test Iteratively: When building complex transformations, add one Set Node at a time and test its output. This makes debugging much easier.
- Leverage Expressions: Don’t be afraid of expressions. They are the key to dynamic and powerful data manipulation. The n8n expression editor provides helpful suggestions.
- Chain Set Nodes: For very complex transformations, it’s often cleaner to use multiple Set Nodes in sequence, each performing a specific, logical step (e.g., one to rename, one to add calculated fields, one to clean up).
- Use
null
andundefined
Carefully: Sometimes you want to explicitly set a field tonull
. Remember thatundefined
means the field doesn’t exist, whilenull
means it exists but has no value.
Conclusion 🎉
The n8n Set Node is a deceptively powerful tool in your automation arsenal. By mastering its various operations—adding, renaming, removing, and especially using dynamic expressions—you can transform raw, messy data into perfectly structured information ready for any destination.
No more manual data cleanup! No more integration headaches due to mismatched field names! With the examples above, you now have a solid foundation to tackle almost any data processing challenge within your n8n workflows.
Start experimenting with these examples in your own n8n instance today. You’ll quickly discover how much time and effort the humble Set Node can save you! Happy automating! 🚀