D: Handling complex data transformations in automation workflows can be challenging. But with n8n’s Set Node, you can manipulate, combine, and structure data like a pro! π― In this guide, weβll explore 10 practical use cases of the Set Node to supercharge your workflows.
πΉ What is the Set Node?
The Set Node in n8n allows you to:
β Add, remove, or modify fields in your JSON data.
β Merge multiple inputs into a single output.
β Transform data structures for APIs, databases, or external tools.
π 10 Powerful Set Node Use Cases
1οΈβ£ Combine Data from Multiple Sources
Scenario: You want to merge customer details from a CRM (HubSpot) with order data (Shopify).
// Input 1 (CRM): { "name": "John Doe", "email": "john@example.com" }
// Input 2 (Shopify): { "order_id": "12345", "product": "Laptop" }
// Set Node Configuration:
"Output": {
"customer": "={{ $input1.json.name }}",
"contact": "={{ $input1.json.email }}",
"purchase": "={{ $input2.json.product }}"
}
// Output:
{ "customer": "John Doe", "contact": "john@example.com", "purchase": "Laptop" }
2οΈβ£ Flatten Nested JSON for Simpler Processing
Scenario: You receive deeply nested API responses and need a cleaner format.
// Input: { "user": { "profile": { "name": "Alice", "age": 30 } } }
// Set Node: Extract "name" and "age" to the root level.
"Output": {
"name": "={{ $input.json.user.profile.name }}",
"age": "={{ $input.json.user.profile.age }}"
}
// Output: { "name": "Alice", "age": 30 }
3οΈβ£ Add Conditional Fields
Scenario: Only include a “discount” field if the order total exceeds $100.
// Input: { "order_total": 150 }
// Set Node:
"Output": {
"total": "={{ $input.json.order_total }}",
"discount": "={{ $input.json.order_total > 100 ? '10%' : null }}"
}
// Output: { "total": 150, "discount": "10%" }
4οΈβ£ Convert Data Types (String β Number)
Scenario: An API returns numeric values as strings, but you need them as numbers.
// Input: { "price": "99.99" }
// Set Node:
"Output": {
"price": "={{ Number($input.json.price) }}"
}
// Output: { "price": 99.99 }
5οΈβ£ Create Custom Error Messages
Scenario: Validate form submissions and return user-friendly errors.
// Input: { "email": "invalid-email" }
// Set Node:
"Output": {
"email": "={{ $input.json.email }}",
"error": "={{ !$input.json.email.includes('@') ? 'Invalid email format' : '' }}"
}
// Output: { "email": "invalid-email", "error": "Invalid email format" }
6οΈβ£ Generate Dynamic Timestamps
Scenario: Log when a workflow runs with a timestamp.
// Set Node:
"Output": {
"event": "Data processed",
"timestamp": "={{ new Date().toISOString() }}"
}
// Output: { "event": "Data processed", "timestamp": "2023-11-15T12:00:00Z" }
7οΈβ£ Merge Arrays from Different Sources
Scenario: Combine two lists of products into one catalog.
// Input 1: { "products": ["Laptop", "Phone"] }
// Input 2: { "items": ["Monitor", "Keyboard"] }
// Set Node:
"Output": {
"all_products": "={{ $input1.json.products.concat($input2.json.items) }}"
}
// Output: { "all_products": ["Laptop", "Phone", "Monitor", "Keyboard"] }
8οΈβ£ Mask Sensitive Data
Scenario: Hide credit card numbers in logs.
// Input: { "card": "1234-5678-9012-3456" }
// Set Node:
"Output": {
"card": "={{ '****-****-****-' + $input.json.card.slice(-4) }}"
}
// Output: { "card": "****-****-****-3456" }
9οΈβ£ Calculate Derived Values
Scenario: Compute tax based on subtotal.
// Input: { "subtotal": 200 }
// Set Node:
"Output": {
"subtotal": "={{ $input.json.subtotal }}",
"tax": "={{ $input.json.subtotal * 0.1 }}",
"total": "={{ $input.json.subtotal * 1.1 }}"
}
// Output: { "subtotal": 200, "tax": 20, "total": 220 }
π Rename Fields for Consistency
Scenario: Standardize keys before sending to a database.
// Input: { "FirstName": "Emma", "user_age": 28 }
// Set Node:
"Output": {
"name": "={{ $input.json.FirstName }}",
"age": "={{ $input.json.user_age }}"
}
// Output: { "name": "Emma", "age": 28 }
π Final Tips for Set Node Mastery
β
Use JavaScript expressions (={{ }}
) for dynamic values.
β
Test transformations with the “Execute Node” button.
β
Combine with other nodes like Function or IF for advanced logic.
With these 10 Set Node techniques, you can handle almost any data transformation in n8n! π Which one will you try first?
π¬ Letβs Discuss! Have a unique Set Node use case? Share it in the comments! π