D: The Set Node in n8n is one of the most powerful yet underrated tools for data manipulation 🔧. It allows you to modify, add, or remove data fields with surgical precision. Let’s explore 10 real-world examples that will transform how you work with data!
1️⃣ Understanding the Basics
The Set Node sits in the “Data Transformation” category and comes with three modes:
- “Add”: Insert new fields
- “Remove”: Delete existing fields
- “Keep Only”: Preserve only specified fields
👉 Example: When receiving API data with 20 fields but only needing 3, use “Keep Only” mode.
2️⃣ Simple Value Assignment
{
"operation": "add",
"values": {
"status": "processed",
"timestamp": "={{$now}}"
}
}
This adds two new fields:
- Static value (“processed”)
- Dynamic value (current timestamp) ⏰
3️⃣ Advanced JSON Manipulation
Need to nest data? Use dot notation:
{
"user.meta.preferences.theme": "dark"
}
Creates a structured object:
{
"user": {
"meta": {
"preferences": {
"theme": "dark"
}
}
}
}
4️⃣ Conditional Field Setting
Combine with IF Node for powerful logic:
- First, evaluate condition
- Then use Set Node to:
{ "discount": "={{ $node["IF"].json["isVIP"] ? 20 : 5 }}%" }
VIP customers get 20% off, others get 5% 💰
5️⃣ Bulk Field Renaming
Receiving data with awkward field names? Standardize them:
{
"operation": "add",
"values": {
"customerName": "={{ $input.item["user_full_name"] }}",
"orderTotal": "={{ $input.item["cart_value"] }}"
}
},
{
"operation": "remove",
"values": ["user_full_name", "cart_value"]
}
6️⃣ Data Type Conversion
Transform strings to numbers or dates:
{
"price": "={{ Number($input.item["price_string"]) }}",
"deliveryDate": "={{ new Date($input.item["delivery_date_string"]) }}"
}
Essential for math operations 📊
7️⃣ Array Element Processing
Working with arrays? Process each element:
{
"products[]": {
"finalPrice": "={{ $input.item["price"] * 0.9 }}"
}
}
Applies 10% discount to all products in array 🛒
8️⃣ Environment Variable Integration
Safely inject secrets or configs:
{
"apiKey": "={{ $env.N8N_API_KEY }}",
"environment": "={{ $env.N8N_ENV }}"
}
No hardcoded credentials! 🔒
9️⃣ Data Aggregation
Combine multiple fields:
{
"fullAddress": "={{ $input.item["street"] + ', ' + $input.item["city"] + ' ' + $input.item["zip"] }}"
}
Perfect for generating complete addresses 🏠
🔟 Workflow Metadata Tagging
Add tracking information:
{
"_workflow": {
"name": "={{ $workflow.name }}",
"executionId": "={{ $execution.id }}",
"timestamp": "={{ $now }}"
}
}
Helps with debugging and auditing 🕵️♂️
Pro Tips 💡
- Expression Preview: Always test expressions using the “👁️” icon
- Dot Notation: Works for both adding and removing nested fields
- Performance: Bulk operations in one Set Node are faster than multiple nodes
- Documentation: Use the “?” button for context-specific help
Common Pitfalls ❌
- Forgetting to remove old fields after renaming
- Not handling undefined values in expressions
- Over-nesting data structures
- Ignoring data type conversions
The Set Node becomes exponentially more powerful when you combine it with other nodes like Function, IF, or Merge. What creative ways have you used the Set Node? Share your examples below! 👇
🚀 Ready to automate like a pro? Try implementing these examples in your next workflow!