Overview
In this tutorial, you will learn how to use the Set node (also known as the Edit Fields node) in n8n to manipulate, format, and clean your workflow data. This node is essential for streamlining your data by adding new fields, combining existing ones, removing unnecessary information, and applying conditional logic to ensure data consistency and enhance automation efficiency.
The Set node is often used alongside other nodes like the HTTP Request Node in n8n, which helps you fetch data from APIs before transforming it with the Set node.
What is the Set Node in n8n?
The Set node allows you to:
- Add new fields or modify existing ones.
- Remove unwanted fields from your data set.
- Clean and standardize data (e.g., replace null or NaN values).
- Format data for consistency (e.g., converting strings to uppercase).
- Apply conditional logic using expressions for dynamic data transformation.
This node is critical when you want to tailor your data before passing it to other nodes in your workflow.
Using the Set Node: Step-by-Step Examples
1. Adding a Full Name Field by Combining First and Last Names
Suppose you have incoming data with separate firstName and lastName fields, but you want to combine these into a single fullName field for easier usage later in your workflow.
Steps:
Add the Set Node
- Click the
+icon on the canvas. - Search for
SetorEdit Fieldsand add the node to your workflow.
- Click the
Configure Node Mode
- Open the node and select Manual Mapping mode (instead of JSON mode) to add fields one by one.
Add a New Field
- Click
Add Field. - Set the Field Name to
full_name(use your naming conventions). - Set the Field Type to
String.
- Click
Create the Expression for Full Name
- Click the value input box to switch it to expression mode.
- Drag the
firstNamefield from the input panel into the expression editor. This inserts{{$json["firstName"]}}. - Manually add a space
" "and then drag thelastNamefield similarly, resulting in:{{$json["firstName"] + " " + $json["lastName"]}}
Include Other Fields
- Enable the option
Include Other Fieldsto keep all other input data intact.
- Enable the option
Exclude Original Fields
- Change the option from
Include AlltoExclude Selected. - Add
firstName,lastNameto the exclude list to remove these fields from the output.
- Change the option from
Save and Execute
- Save the node and run the workflow.
- Verify the output contains
full_nameand all other fields exceptfirstNameandlastName.
Result Example
{
"full_name": "John Doe",
"email": "john.doe@example.com",
"company": "Acme Corp"
}
2. Adding Conditional Logic: Tagging Order Priority Based on Order Date
You can also use the Set node to add fields based on conditions. For example, tag orders as high or standard priority depending on whether the order date is older than 45 days.
Steps:
Add a New Field for Priority
- Click
Add Field. - Name the field
order_priority. - Set the type to
String.
- Click
Open Expression Editor
- Click on the value field and open the expression editor (click the gear icon and select "Add Expression").
Write a Ternary Expression
The ternary expression allows you to evaluate a condition and return one of two values.Here's the basic syntax:
{{ condition ? "valueIfTrue" : "valueIfFalse" }}Calculate Days Since Order Date
Use built-in date functions available in n8n's expression editor:{{$now.diff(new Date($json["order_date"]), 'days') > 45 ? "high" : "standard"}}Explanation:
$nowgets the current date/time..diff()calculates the difference in days between the current date and theorder_date.- If the difference is more than 45 days, return
"high", else"standard".
Save and Test
- Save the expression.
- Run the workflow and check that orders older than 45 days are marked as
highpriority.
Example Output
{
"full_name": "Jane Smith",
"order_date": "2023-01-15",
"order_priority": "high"
}
Understanding Set Node Modes: Manual Mapping vs JSON Mode
The Set node offers two modes for defining output fields:
Manual Mapping Mode
- Add or modify fields individually.
- Use the UI to add fields, select types, and define expressions.
- Easier for most use cases and visual clarity.
JSON Mode
- Directly write the complete JSON structure for the output.
- Overrides all input data and starts fresh.
- Useful when you want to completely redefine the output structure.
Tip: Use manual mapping mode when you want to retain some input fields and add or modify specific fields. Use JSON mode when you want full control over the output JSON.
For more advanced workflow control and collaboration, consider exploring how to Scale n8n with Enterprise Features.
Best Practices for Using the Set Node
- Use expressions to dynamically build or transform data—don't hardcode values unless necessary.
- Always check your field names and types to maintain consistency throughout your workflow.
- Exclude unnecessary fields to optimize performance and reduce clutter.
- Test your expressions using the node's "Execute Node" or "Test" functionality before connecting downstream nodes.
- Document your expressions with comments or clear naming to help future maintenance.
Common Mistakes and Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Output only shows new fields, missing original data | Include Other Fields option not enabled or set incorrectly |
Enable Include Other Fields or select Include All/Selected appropriately |
| Expression syntax errors | Incorrect use of expression editor or missing curly braces | Use double curly braces {{ }} for expressions and verify syntax in the editor |
| Fields not excluded as expected | Wrong field names or format in the exclude list | Ensure field names are comma-separated without extra spaces and match exactly the input keys |
| Date calculations incorrect | Incorrect date formats or missing new Date() in expressions |
Wrap string dates with new Date() and confirm date strings are ISO formatted |
| Unexpected data types in output | Setting wrong field type in Set node |
Always set the correct field type (string, number, boolean, array, object) matching your data |
Additional Tips: Combining Drag-and-Drop with Expressions
- You can drag input fields directly into the expression editor to avoid typos.
- Mixing fixed strings and expressions is possible; for example:
{{$json["firstName"] + " " + $json["lastName"].toUpperCase()}}
- Use JavaScript methods like
.toUpperCase(),.trim(),.toLowerCase()to format strings.
Useful n8n Documentation Links
- Set Node Documentation
- Expressions in n8n
- For API integrations, refer to the n8n API documentation and learn about managing your credentials securely with the n8n Credentials documentation.
Quick Reference Cheat Sheet for Set Node Usage
| Action | How to Do It |
|---|---|
| Add new field | Click Add Field, name it, select type, and set value or expression |
| Combine fields | Use expressions like {{$json["field1"] + " " + $json["field2"]}} |
| Exclude unwanted fields | Use Exclude Selected option and list fields comma-separated |
| Include all other fields | Enable Include Other Fields and choose Include All or Selected |
| Use conditional logic | Write ternary expressions in value: {{ condition ? "trueVal" : "falseVal" }} |
| Switch to JSON mode | Select JSON mode and write entire output JSON structure |
| Access current date/time | Use $now expression |
| Calculate date difference | Use $now.diff(new Date($json["dateField"]), 'days') |
By mastering the Set node, you gain powerful control over your workflow data, enabling cleaner, more efficient, and smarter automation. As shown in the video above, this node is a cornerstone of complex n8n workflows and will help you maintain data integrity and streamline processing throughout your automations.
For a broader perspective on automation platforms, check out our comparison of n8n vs Zapier vs Make.com.