D: The Set node in n8n is one of the most versatile tools for manipulating, transforming, and restructuring data in your workflows. Whether you’re a beginner or an advanced user, mastering this node can significantly enhance your automation capabilities.
In this comprehensive guide, weβll explore:
β What the Set Node Does
β Key Features & Configuration Options
β 10 Practical Use Cases (with examples!)
β Pro Tips & Best Practices
Letβs dive in! πββοΈ
π What is the Set Node?
The Set node allows you to:
β
Add new fields to your data
β
Modify existing values
β
Delete unwanted fields
β
Restructure JSON objects
Itβs like a Swiss Army knife π for data transformation in n8n!
βοΈ How to Configure the Set Node
When you add a Set node, youβll see these key options:
1. Mode (Choose how data is modified)
- “Set” β Overwrites or adds new fields
- “Remove” β Deletes specified fields
- “Keep Only” β Keeps only selected fields
2. Value Type (How to assign data)
- “String” β Plain text
- “Number” β Numeric values
- “Boolean” β True/False
- “JSON” β Structured data
3. Include in Output
- Toggle whether to pass modified data forward
π― 10 Powerful Use Cases for the Set Node
1. Adding Timestamps to Records
π Use Case: Automatically log when a record is processed.
βοΈ Setup:
{
"timestamp": "={{ $now.toISOString() }}"
}
2. Renaming Fields for API Compatibility
π Use Case: Adjust field names before sending to another service.
βοΈ Setup:
{
"user_id": "={{ $input.item.id }}",
"email_address": "={{ $input.item.email }}"
}
3. Combining Multiple Fields
π Use Case: Merge first & last names into a full name.
βοΈ Setup:
{
"full_name": "={{ $input.item.first_name }} {{ $input.item.last_name }}"
}
4. Removing Sensitive Data
π Use Case: Strip out passwords before logging.
βοΈ Mode: “Remove”
βοΈ Fields: ["password", "credit_card"]
5. Setting Default Values
π Use Case: Ensure a field always has a fallback value.
βοΈ Setup:
{
"status": "={{ $input.item.status || 'pending' }}"
}
6. Converting Data Types
π Use Case: Change a string to a number for calculations.
βοΈ Setup:
{
"price": "={{ Number($input.item.price_str) }}"
}
7. Flattening Nested JSON
π Use Case: Simplify complex API responses.
βοΈ Setup:
{
"user_name": "={{ $input.item.user.profile.name }}",
"user_email": "={{ $input.item.user.contact.email }}"
}
8. Conditional Field Assignment
π Use Case: Apply discounts only if eligible.
βοΈ Setup:
{
"discount_price": "={{ $input.item.is_member ? $input.item.price * 0.9 : $input.item.price }}"
}
9. Creating Arrays from Strings
π Use Case: Split tags into an array.
βοΈ Setup:
{
"tags": "={{ $input.item.tags_str.split(',') }}"
}
10. Generating Custom IDs
π Use Case: Create unique identifiers.
βοΈ Setup:
{
"custom_id": "={{ 'CUST-' + $input.item.id + '-' + Date.now() }}"
}
π‘ Pro Tips for Using the Set Node
πΉ Use JavaScript expressions (={{ ... }}
) for dynamic values.
πΉ Chain multiple Set nodes for complex transformations.
πΉ Test with sample data before full execution.
πΉ Combine with Function nodes for advanced logic.
οΏ½ Conclusion
The Set node is a game-changer for data manipulation in n8n. Whether you’re cleaning data, reformatting API responses, or adding metadata, mastering this tool will make your workflows more efficient and flexible.
π¬ Got questions? Drop them in the comments!
π Found this useful? Share with fellow automators!
Happy automating! π€β¨
π Further Reading:
Would you like a deep dive into any specific use case? Let me know! π