n8n Set Node Guide: Add, Edit & Clean Data Fields | Complete Tutorial

Complete guide to the n8n Set node (Edit Fields). Learn to add new fields, rename keys, remove data, and format values with real workflow examples.

Table of Contents

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:

  1. Add the Set Node

    • Click the + icon on the canvas.
    • Search for Set or Edit Fields and add the node to your workflow.
  2. Configure Node Mode

    • Open the node and select Manual Mapping mode (instead of JSON mode) to add fields one by one.
  3. Add a New Field

    • Click Add Field.
    • Set the Field Name to full_name (use your naming conventions).
    • Set the Field Type to String.
  4. Create the Expression for Full Name

    • Click the value input box to switch it to expression mode.
    • Drag the firstName field from the input panel into the expression editor. This inserts {{$json["firstName"]}}.
    • Manually add a space " " and then drag the lastName field similarly, resulting in:
      {{$json["firstName"] + " " + $json["lastName"]}}
      
  5. Include Other Fields

    • Enable the option Include Other Fields to keep all other input data intact.
  6. Exclude Original Fields

    • Change the option from Include All to Exclude Selected.
    • Add firstName,lastName to the exclude list to remove these fields from the output.
  7. Save and Execute

    • Save the node and run the workflow.
    • Verify the output contains full_name and all other fields except firstName and lastName.

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:

  1. Add a New Field for Priority

    • Click Add Field.
    • Name the field order_priority.
    • Set the type to String.
  2. Open Expression Editor

    • Click on the value field and open the expression editor (click the gear icon and select "Add Expression").
  3. 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" }}
    
  4. 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:

    • $now gets the current date/time.
    • .diff() calculates the difference in days between the current date and the order_date.
    • If the difference is more than 45 days, return "high", else "standard".
  5. Save and Test

    • Save the expression.
    • Run the workflow and check that orders older than 45 days are marked as high priority.

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.


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.

Frequently Asked Questions

Use the Set node in Manual Mapping mode to add a new field, then create an expression combining firstName and lastName like {{$json["firstName"] + " " + $json["lastName"]}}.

Yes, by enabling 'Include Other Fields' and setting the option to 'Exclude Selected', you can specify fields like firstName and lastName to be removed from the output.

You can use expressions with conditional statements inside the Set node fields to dynamically set values based on other data, such as tagging order priority based on order date.

Yes, the Set node allows you to replace null or NaN values, format strings (e.g., convert to uppercase), and apply other transformations to ensure data consistency.

Manual Mapping lets you add or edit fields one by one with a user-friendly interface, while JSON mode allows you to edit the entire JSON structure directly for advanced use cases.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources