DEV Community

Pirate Prentice
Pirate Prentice

Posted on

n8n Set Node: How to Add, Update, and Transform Workflow Data (Free JSON)

If you've built more than two n8n workflows, you've hit the same wall: you have data coming in from one node, but the shape is wrong. Fields are named incorrectly, you need to add a static value, or you want to drop everything except three fields before passing data downstream.

The Set node is the answer to all of those problems. It's one of the most-used nodes in n8n — and one of the most misunderstood by beginners.

This article covers everything you need: what the Set node actually does, how to use both "Manual Mapping" and "JSON" modes, common patterns, and a free workflow JSON you can import today.


What the n8n Set Node Does

The Set node lets you:

  • Add new fields to your items (fixed values or expressions)
  • Rename existing fields by setting a new field from an old one
  • Delete fields you don't need downstream
  • Override field values with static text, numbers, or dynamic expressions
  • Reshape your data entirely in JSON mode

It's essentially a "transform" step — it takes whatever is in your workflow at that point and outputs exactly what you specify.


The Two Modes

Manual Mapping Mode (Default)

This is the visual, field-by-field approach. You click Add Field, pick a name and type, and set a value.

Supported types: String, Number, Boolean, Array, Object, DateTime

Example: You're receiving a webhook with a field called full_name but your CRM expects name. In Manual Mapping mode:

  • Field name: name
  • Value: {{ $json.full_name }}

That's it — the Set node outputs name with the value from full_name.

"Keep All Unknown Fields" toggle: This is the critical setting beginners miss.

  • ON (default): All existing fields from the incoming item are preserved, plus your new fields are added/overridden
  • OFF: Only the fields you explicitly define are in the output — everything else is dropped

Turn it OFF when you want a clean output with only the fields you specified. Leave it ON when you're adding or updating just a few fields and want the rest to pass through.

JSON Mode

For more complex reshaping, switch to JSON mode. You write raw JSON (with expressions allowed) and that becomes the output item.

JSON mode is best when:

  • You're completely restructuring the data shape
  • You want to nest fields into objects
  • The output schema is complex or has many fields

Common Set Node Patterns

Pattern 1: Add a Static Field

You want to tag every item with a source field for tracking.

  • Mode: Manual Mapping, Keep All Unknown Fields: ON
  • Add Field → source (String) → "n8n-automation"

Every item now has source: "n8n-automation" alongside its existing fields.

Pattern 2: Rename a Field

Your API returns user_id but your next node expects userId.

  • Add Field → userId (String) → {{ $json.user_id }}
  • To drop user_id, turn off "Keep All Unknown Fields" and only define userId (plus any fields you want to keep)

Pattern 3: Flatten Nested Data

Webhook delivers { "user": { "name": "Alice", "email": "alice@example.com" } } and you want flat fields.

Set node, Manual Mapping:

  • name{{ $json.user.name }}
  • email{{ $json.user.email }}
  • Keep All Unknown Fields: OFF

Pattern 4: Add a Computed Field

You have price and quantity and want to add total.

  • Add Field → total (Number) → {{ $json.price * $json.quantity }}
  • Keep All Unknown Fields: ON

Pattern 5: Clean Up Before an API Call

Use Set node with Keep All Unknown Fields OFF and list only the fields the API accepts. Protects against unexpected-field rejections.


Set Node vs Code Node

Task Set Node Code Node
Add/rename/drop fields Yes Overkill
Static values or simple expressions Yes Overkill
Conditional field logic No Yes
Loop over nested arrays No Yes
Complex string manipulation No Yes

Rule of thumb: if you can express it as {{ expression }} without a loop, use Set. If you need if/else logic or loops inside the item, use Code.


Free Workflow JSON: Data Cleanup Pipeline

Import this into n8n (Menu → Import from JSON) to see all four patterns in action:

{
  "name": "Set Node Patterns Demo",
  "nodes": [
    {
      "parameters": { "mode": "runOnceForEachItem", "jsCode": "return { json: { user: { name: 'Alice', email: 'alice@example.com' }, price: 49, quantity: 3, user_id: 'u_001' } };" },
      "name": "Mock Input", "type": "n8n-nodes-base.code", "position": [200, 300], "typeVersion": 2
    },
    {
      "parameters": { "mode": "manual", "assignments": { "assignments": [{ "name": "total", "value": "={{ $json.price * $json.quantity }}", "type": "number" }] }, "options": {} },
      "name": "Add Computed Total", "type": "n8n-nodes-base.set", "position": [420, 300], "typeVersion": 3.4
    },
    {
      "parameters": { "mode": "manual", "assignments": { "assignments": [{ "name": "name", "value": "={{ $json.user.name }}", "type": "string" }, { "name": "email", "value": "={{ $json.user.email }}", "type": "string" }, { "name": "userId", "value": "={{ $json.user_id }}", "type": "string" }, { "name": "total", "value": "={{ $json.total }}", "type": "number" }] }, "options": { "includeOtherFields": false } },
      "name": "Clean for API", "type": "n8n-nodes-base.set", "position": [640, 300], "typeVersion": 3.4
    }
  ],
  "connections": {
    "Mock Input": { "main": [[{ "node": "Add Computed Total", "type": "main", "index": 0 }]] },
    "Add Computed Total": { "main": [[{ "node": "Clean for API", "type": "main", "index": 0 }]] }
  }
}
Enter fullscreen mode Exit fullscreen mode

Tips & Gotchas

Gotcha 1: Field type coercion
If you set a Number field to {{ $json.count }} and the value is "42" (string), you get 42 (number). But "forty-two" becomes NaN. Confirm your source data types.

Gotcha 2: v2 vs v3 Set node
Older imported workflows may have typeVersion: 2 Set nodes (legacy "Add Values" interface). They still work, but n8n will prompt you to upgrade — usually safe to accept.

Tip: Use Set node for debugging
Drop a Set node in JSON mode with value {{ $json }} to inspect data shape mid-workflow without changing anything. Remove before production.

Tip: Chain Set nodes freely
Set nodes add no meaningful latency. Chain two or three in a row for readability — it's better than one monster node with fifteen fields.


Want Pre-Built Workflow Packs?

If you'd rather import production-ready workflows that already include proper Set node usage, error handling, and documentation: n8n Workflow Starter Pack on Gumroad — 3 real workflows, $29 one-time.


Questions about the Set node? Drop them in the comments — happy to help with your specific use case.

Top comments (1)

Collapse
 
pirateprentice profile image
Pirate Prentice

Quick question for n8n builders: which Set node pattern catches you out most often?

For me it was Pattern 3 (flatten nested data) — I kept forgetting to turn off "Keep All Unknown Fields" and ending up with both the nested user object AND the flat name/email fields in my output. Double data, downstream confusion.

What's your most common Set node mistake?