일. 8월 17th, 2025

G: n8n Logo

In the vast universe of data, raw information often resembles an untamed wilderness. It comes in various shapes, sizes, and sometimes, with unwanted baggage. To truly harness its power, you need the right tools to sculpt, refine, and prepare it for its ultimate purpose. Enter the n8n Set node – a deceptively simple yet incredibly powerful cornerstone in your automation workflows.

This comprehensive guide will demystify the n8n Set node, providing a detailed explanation, exploring its core operations, and presenting 10 practical, real-world use cases to elevate your data handling game. Get ready to transform your data like a pro! 🚀


1. What is the n8n Set Node? The Data Sculptor’s Secret Weapon 🗿

At its core, the n8n Set node is a data transformation tool. It allows you to manipulate the JSON data passing through your workflow. Think of it as your data’s personal stylist 👗 – you can add new accessories (fields), remove old, irrelevant items (fields), update existing features, or even completely redefine its look.

Why is it so crucial? 🤔

  • Data Preparation: Before sending data to an API, database, or email, it often needs to be in a specific format.
  • Consistency: Standardize field names across different sources.
  • Reduced Payload: Remove unnecessary data to make requests faster and more efficient.
  • Calculations: Perform simple calculations to derive new fields.
  • Debugging: Temporarily add fields to inspect data flow.

The Set node operates on each individual item (or item in a batch) that flows into it. This means if you have 10 items entering the node, the operations you define will be applied to all 10 items independently.


2. Deep Dive: Core Operations of the Set Node 🛠️

The Set node offers three primary modes of operation, each serving a distinct purpose in data manipulation:

2.1. Add/Update Value ➕

This is the most frequently used operation. It allows you to:

  • Add a completely new field to your data item.
  • Update the value of an existing field.

How it works: You define a “Key” (the field name) and a “Value” (the data you want to assign to that field). The value can be a static string, a number, a boolean, or most powerfully, an expression that references other data in the current item or even from previous nodes.

Example: Adding a New Field Let’s say you receive product data, and you want to add a status field indicating it’s “processed”.

  • Input Data:
    [
      {
        "json": {
          "productName": "Laptop",
          "price": 1200
        }
      }
    ]
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: status
      • Value: processed (Type: String)
  • Output Data:
    [
      {
        "json": {
          "productName": "Laptop",
          "price": 1200,
          "status": "processed"
        }
      }
    ]

Example: Updating an Existing Field with an Expression You want to apply a 10% discount to all product prices.

  • Input Data: (Same as above)
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: price
      • Value: {{ $json.price * 0.9 }} (Type: Expression)
  • Output Data:
    [
      {
        "json": {
          "productName": "Laptop",
          "price": 1080, // 1200 * 0.9
          "status": "processed" // If you kept the previous 'status' addition
        }
      }
    ]

    Note: When you use an existing key, the Set node will overwrite its value.

2.2. Keep Only Set ✂️

This operation acts as a data filter, allowing you to explicitly define which fields you want to keep in your item. All other fields will be removed. This is incredibly useful for:

  • Reducing data payload: Only send what’s absolutely necessary.
  • Enforcing schema: Ensure downstream systems only receive expected fields.

How it works: You list the keys (field names) you wish to retain.

Example: You only need the name and email from a large user object.

  • Input Data:
    [
      {
        "json": {
          "id": "usr_123",
          "name": "Alice Wonderland",
          "email": "alice@example.com",
          "address": "123 Rabbit Hole",
          "phone": "555-1234",
          "lastLogin": "2023-10-27T10:00:00Z"
        }
      }
    ]
  • Set Node Configuration:
    • Operation: Keep Only Set
    • Keys to Keep:
      • name
      • email
  • Output Data:
    [
      {
        "json": {
          "name": "Alice Wonderland",
          "email": "alice@example.com"
        }
      }
    ]

    Notice how id, address, phone, and lastLogin are all gone.

2.3. Remove Value 🗑️

This operation is the opposite of “Keep Only Set.” It allows you to explicitly define which fields you want to remove from your data item. All other fields remain untouched. This is ideal for:

  • Cleaning up sensitive data: Remove passwords, API keys, or internal IDs.
  • Stripping unnecessary metadata: Remove fields like __v or _id often added by databases if not needed downstream.

How it works: You list the keys (field names) you wish to remove.

Example: Remove an internal secretKey and a database-specific _id field.

  • Input Data:
    [
      {
        "json": {
          "productName": "Widget",
          "price": 50,
          "secretKey": "my-hidden-key-123",
          "_id": "653b6d9a1c2d3e4f5a6b7c8d"
        }
      }
    ]
  • Set Node Configuration:
    • Operation: Remove Value
    • Keys to Remove:
      • secretKey
      • _id
  • Output Data:
    [
      {
        "json": {
          "productName": "Widget",
          "price": 50
        }
      }
    ]

3. Advanced Concepts & Best Practices ✨

To truly master the Set node, understand these nuances:

3.1. Expressions: The Powerhouse of Transformation ⚡

Expressions are JavaScript-like snippets enclosed in double curly braces {{ }} that allow you to dynamically calculate values.

  • {{ $json.fieldName }}: Accesses the value of fieldName within the current item’s JSON data. This is your most common way to reference data.
  • {{ $node["Node Name"].json.fieldName }}: Accesses data from a specific node earlier in the workflow. Be careful with this, as it can make workflows harder to read and debug if overused for cross-node referencing when Add/Update and chaining are better.
  • {{ $input.item.json.fieldName }}: This is functionally identical to $json.fieldName for accessing the current item’s JSON data. It’s often seen in older tutorials but $json is generally preferred for brevity.
  • Basic Arithmetic: {{ $json.price * $json.quantity }}
  • String Concatenation: {{ $json.firstName + ' ' + $json.lastName }}
  • Conditional Logic (simple): {{ $json.price > 100 ? 'Expensive' : 'Cheap' }} (For complex logic, an If node is usually better).
  • Date Formatting (using n8n’s built-in functions): {{ $json.timestamp.toDate().toLocaleString() }}

3.2. Working with Nested Data Structures 🎯

The Set node handles nested JSON objects gracefully using dot notation.

  • Accessing Nested Data: If you have {"user": {"profile": {"email": "test@example.com"}}}, you can access the email with {{ $json.user.profile.email }}.
  • Setting Nested Data: You can also create or update nested structures by using dot notation as the “Key”.
    • Key: userDetails.contact.email
    • Value: {{ $json.email }} This will create an object userDetails which contains contact, which then contains email.

3.3. Chaining Set Nodes 🔗

Don’t feel limited to a single Set node. For complex transformations, it’s often clearer and more manageable to chain multiple Set nodes together.

  • First Set Node: Adds/updates foundational fields.
  • Second Set Node: Uses the output of the first to perform calculations or further transformations.
  • Third Set Node: Filters or removes unwanted fields for the final payload.

This improves readability and makes debugging easier, as each node focuses on a specific transformation step.

3.4. Performance Considerations 📊

While Set nodes are efficient, be mindful when processing extremely large datasets or performing complex calculations on every item.

  • “Keep Only Set” vs. “Remove Value”: If you only need a few fields out of many, “Keep Only Set” is generally more efficient than listing every field to “Remove Value.” Conversely, if you only need to remove a few fields, “Remove Value” is better.
  • Complex Expressions: Very complex JavaScript expressions might be better handled in a Function node if they involve multiple lines of code or external libraries. However, for most common transformations, the Set node is perfectly capable.

4. 10 Powerful Use Cases for the n8n Set Node 💡

Let’s dive into practical scenarios where the Set node truly shines. For each, we’ll provide a brief description, an example of how you’d configure the Set node, and the expected transformation.

Use Case 1: Standardizing Field Names (Renaming) ✍️

Often, data from different sources will use inconsistent field names (e.g., customerName, client_name, userFullName). The Set node helps standardize them.

  • Scenario: An API returns customer_name, but your database requires fullName.
  • Set Node Configuration:
    1. Operation: Add/Update Value
      • Key: fullName
      • Value: {{ $json.customer_name }}
    2. Operation: Remove Value
      • Key: customer_name
  • Input Example: {"id": 123, "customer_name": "John Doe", "email": "john@example.com"}
  • Output Example: {"id": 123, "fullName": "John Doe", "email": "john@example.com"}

Use Case 2: Cleaning Up Unnecessary Data 🗑️

Remove fields that are not needed by downstream systems, saving bandwidth and decluttering your data.

  • Scenario: A webhook receives data with internal IDs (_id, __v) or debug information you don’t want to store.
  • Set Node Configuration:
    • Operation: Remove Value
    • Keys to Remove: _id, __v, debugInfo
  • Input Example: {"product": "Book", "price": 20, "_id": "abc123", "__v": 0, "supplier_id": "sup-456"}
  • Output Example: {"product": "Book", "price": 20, "supplier_id": "sup-456"}

Use Case 3: Adding Default or Static Values ➕

Inject new fields with fixed values that apply to all items.

  • Scenario: You’re sending customer data to a CRM and want to tag all new entries with a source field like “n8n_automation”.
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: source
      • Value: n8n_automation (Type: String)
      • Key: isActive
      • Value: true (Type: Boolean)
  • Input Example: {"name": "Jane Doe", "email": "jane@example.com"}
  • Output Example: {"name": "Jane Doe", "email": "jane@example.com", "source": "n8n_automation", "isActive": true}

Use Case 4: Data Type Conversion & Formatting 🔠➡️🔢

Although n8n often handles types automatically, you might need to force a type or format a string.

  • Scenario: An API returns price as a string ("100.50"), but you need it as a number for calculations. Or you need a number to be a string for a text field.
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: numericPrice
      • Value: {{ parseFloat($json.price) }} (Type: Expression)
      • Key: priceString
      • Value: {{ $json.numericPrice.toString() }} (Type: Expression)
  • Input Example: {"item": "Shirt", "price": "49.99"}
  • Output Example: {"item": "Shirt", "price": "49.99", "numericPrice": 49.99, "priceString": "49.99"}

Use Case 5: Calculating New Fields from Existing Ones 🧮

Derive new information from existing fields using expressions.

  • Scenario: You have unitPrice and quantity and need to calculate totalPrice.
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: totalPrice
      • Value: {{ $json.unitPrice * $json.quantity }} (Type: Expression)
      • Key: taxAmount
      • Value: {{ $json.totalPrice * 0.08 }} (Type: Expression) Note: This would require two Set nodes or careful ordering if totalPrice is calculated in the same node.
  • Input Example: {"item": "Mug", "unitPrice": 10, "quantity": 3}
  • Output Example: {"item": "Mug", "unitPrice": 10, "quantity": 3, "totalPrice": 30} (After first Set)

Use Case 6: Extracting & Flattening Nested Data 📦

When data is deeply nested, you might want to bring specific values to the top level for easier access.

  • Scenario: User email is buried in data.user.profile.email. You want a top-level userEmail field.
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: userEmail
      • Value: {{ $json.data.user.profile.email }} (Type: Expression)
  • Input Example: {"id": "xyz", "data": {"user": {"profile": {"email": "user@domain.com", "status": "active"}}}}
  • Output Example: {"id": "xyz", "data": {"user": {"profile": {"email": "user@domain.com", "status": "active"}}}, "userEmail": "user@domain.com"}

Use Case 7: Filtering Specific Fields for Downstream APIs 📧

When sending data to an external API, it often expects a very specific payload structure. “Keep Only Set” is perfect for this.

  • Scenario: You’ve processed customer data and now need to send only firstName, lastName, and contactEmail to an email marketing service.
  • Set Node Configuration:
    • Operation: Keep Only Set
    • Keys to Keep: firstName, lastName, contactEmail
  • Input Example: {"id": 1, "firstName": "Alice", "lastName": "Smith", "contactEmail": "alice@email.com", "address": "123 Main St", "phone": "555-0101"}
  • Output Example: {"firstName": "Alice", "lastName": "Smith", "contactEmail": "alice@email.com"}

Use Case 8: Conditional Field Creation (with IF Node) 🚦

While the Set node itself doesn’t do complex if/else, it works beautifully after an If node to add fields conditionally.

  • Scenario: If an order total is over $100, add a shippingStatus: "Free Shipping" field. Otherwise, add shippingCost: 5.
  • Workflow Structure: Previous Node -> If Node (Condition: {{ $json.orderTotal > 100 }})
    • True Branch: Set Node 1 (Add/Update: shippingStatus: "Free Shipping")
    • False Branch: Set Node 2 (Add/Update: shippingCost: 5)
    • Both branches merge into a Merge Node then continue.
  • Set Node 1 Config (True Branch):
    • Operation: Add/Update Value
    • Key: shippingStatus
    • Value: Free Shipping
  • Set Node 2 Config (False Branch):
    • Operation: Add/Update Value
    • Key: shippingCost
    • Value: 5 (Type: Number)
  • Input Example: {"orderId": "ABC", "orderTotal": 120} (for True) / {"orderId": "DEF", "orderTotal": 80} (for False)
  • Output Example: {"orderId": "ABC", "orderTotal": 120, "shippingStatus": "Free Shipping"} (from True) / {"orderId": "DEF", "orderTotal": 80, "shippingCost": 5} (from False)

Use Case 9: Generating Unique IDs or Timestamps 🆔🗓️

Add unique identifiers or current timestamps to your data.

  • Scenario: You need a recordId for a database entry and a createdAt timestamp.
  • Set Node Configuration:
    • Operation: Add/Update Value
    • Values to Set:
      • Key: recordId
      • Value: {{ $node["Node Name"].id }} or {{ $workflow.id + Date.now() }} (use a unique ID node for better UUIDs)
      • Key: createdAt
      • Value: {{ new Date().toISOString() }} (Type: Expression)
  • Input Example: {"task": "Buy groceries"}
  • Output Example: {"task": "Buy groceries", "recordId": "some_generated_id", "createdAt": "2023-10-27T14:30:00.000Z"}

Use Case 10: Debugging and Inspection 🐛

Temporarily add fields to inspect the state of your data at various points in the workflow.

  • Scenario: You suspect an upstream node isn’t providing the correct price field. Add a debugPrice field to check.
  • Set Node Configuration (temporary):
    • Operation: Add/Update Value
    • Key: debugPrice
    • Value: {{ $json.price }} (or {{ $node["Problem Node"].json.price }})
  • Input Example: {"item": "Widget", "price": 15}
  • Output Example: {"item": "Widget", "price": 15, "debugPrice": 15} Once debugging is done, simply disable or remove this Set node.

Conclusion: Unleash Your Data’s Full Potential! 🌟

The n8n Set node might seem basic at first glance, but as you’ve seen, its versatility makes it an indispensable tool for anyone working with data in n8n. Whether you’re cleaning up messy inputs, preparing data for external APIs, performing calculations, or simply standardizing your information, the Set node is your go-to solution.

By understanding its core operations – Add/Update Value, Keep Only Set, and Remove Value – and leveraging the power of expressions and chaining, you can confidently sculpt your data into the perfect form for any task.

Start experimenting with these use cases in your own workflows, and you’ll quickly discover the profound impact the humble Set node can have on the efficiency and robustness of your automations. Happy automating! 🎉

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다