Assign Values to Variables Using the n8n Set Node
If you spend any time building workflows in n8n, the Set node quickly becomes one of those tools you reach for almost without thinking. It is simple on the surface, but incredibly handy whenever you need to shape, clean, or prepare data as it moves through your automation.
In this guide, we will walk through what the Set node actually does, how to set number, string, and boolean values, how to use expressions for dynamic data, and a few tips to keep your workflows tidy and predictable. Think of it as your friendly cheat sheet for assigning values in n8n.
What Is the Set Node in n8n?
At its core, the Set node lets you control the fields that exist on each item that passes through your workflow. You can:
- Add new fields and variables
- Change or overwrite existing fields
- Remove fields you do not want to keep
That makes it perfect for everyday tasks such as:
- Creating fixed variables like API keys, flags, or counters
- Normalizing data into a consistent schema before it reaches other nodes
- Renaming, combining, or splitting fields to match what another service expects
If you have ever thought, “I just need to tweak this data a bit before sending it on,” the Set node is usually the right answer.
Why Use the Set Node Instead of a Function Node?
You might be wondering, “Couldn’t I just do this in a Function node?” You absolutely can, but the Set node has a few advantages for simple assignments:
- It is visual – you see exactly which fields you are setting without reading code.
- It is safer – you are less likely to break things by accident when all you are doing is assigning values.
- It is faster to configure – especially for basic number, string, or boolean fields.
When you get into complex transformations or heavy logic, a Function node becomes more useful. For simple data shaping and variable assignment, the Set node keeps things clean and easy to understand.
First Look: A Simple Set Node Example
Let us start with a tiny workflow so you can see the Set node in action. This example uses a Manual Trigger followed by a Set node that creates three fields: number, string, and boolean.
{ "nodes": [ { "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger" }, { "name": "Set", "type": "n8n-nodes-base.set", "parameters": { "values": { "number": [ { "name": "number", "value": 20 } ], "string": [ { "name": "string", "value": "From n8n with love" } ], "boolean": [ { "name": "boolean", "value": true } ] } } } ]
}
When you run this workflow, the Set node outputs an item with:
- number: 20
- string: “From n8n with love”
- boolean: true
That is all it does: it takes whatever comes in, adds these three fields, and passes everything along to the next node. Simple, but powerful once you start using it everywhere.
How to Configure the Set Node Step by Step
Let us quickly walk through setting this up in the n8n UI. You do not need any special data source to follow along, just your n8n instance.
1. Add a trigger to test with
For testing, the easiest option is the Manual Trigger node. Drop it on the canvas. This lets you click Execute and immediately see what your workflow outputs.
2. Connect a Set node
Next, drag a Set node onto the canvas and connect it to the Manual Trigger. Open the Set node and you will see a UI where you can define new fields and choose their types.
For each field you want to add, you can:
- Enter a field name
- Pick a type, such as number, string, or boolean
- Provide a value
To recreate the earlier example, you would add:
numberwith value20(type: number)stringwith valueFrom n8n with love(type: string)booleanwith valuetrue(type: boolean)
3. Run the workflow and inspect the output
Click Execute on the Manual Trigger, then open the Set node’s output. You should see the three fields you just created, plus any data that was already on the incoming item.
Once you are comfortable with static values, you are ready for the fun part: expressions.
Using Expressions in the Set Node
Static values are useful, but workflows really shine when your values change based on previous nodes or the current time. That is where expressions come in.
In the Set node, instead of typing a fixed value, you can click into the value field and switch to an expression. A few common patterns:
Reference data from previous nodes
To copy a value from the incoming item, you can use:
{{$json["previousField"]}}
This reads the field previousField from the current item’s JSON and assigns it to your new field.
Use built-in helpers like time functions
Need a timestamp? n8n gives you handy helpers like $now:
{{ $now.toISOString() }}
You can use this in the Set node to store when an item was processed, for example.
Expressions let you compute values dynamically, pull in data from earlier steps, or even do light transformations without writing a full Function node.
Common Set Node Options You Should Know
“Keep Only Set” for a clean payload
One important option you will often see in the Set node is Keep Only Set. When you enable it, the node removes every field that you did not explicitly define in this Set node.
Use this when you want to:
- Send a very specific payload to an API
- Make sure no extra or sensitive fields are passed downstream
- Clean up noisy data from previous nodes
Overwriting existing fields
If the incoming item already has a field with the same name, the Set node will overwrite it. This is extremely useful when you are normalizing data, but it can also cause confusion if you forget it is happening.
If you want to keep the original value, consider:
- Renaming the new field, for example
normalizedPriceinstead ofprice - Copying the old field to something like
priceOriginalbefore overwriting
Keeping data types consistent
Data types matter in n8n. You will save yourself a lot of debugging if you keep them consistent:
- Use numbers for anything you will calculate with.
- Use booleans for flags that you will check in IF or Switch nodes.
- Use strings when you are dealing with text or IDs.
For example, "20" is a string, while 20 is a number. They are not the same when you start doing math or comparisons, so it is worth getting them right at the Set node stage.
Practical Example: Using Set With Expressions
Let us look at a slightly more realistic scenario. Imagine you receive items with a price field as a string, such as "12.50", but you need a numeric field for calculations. You can convert it in the Set node with an expression:
{{ parseFloat($json["price"]) }}
In the Set node, you could define multiple fields at once, for example:
{ "priceNumber": {{ parseFloat($json["price"]) }}, "receivedAt": "{{ $now.toISOString() }}", "isProcessed": false
}
Here is what is happening:
priceNumberbecomes a real number, ready for totals and calculations.receivedAtstores the current timestamp in ISO format.isProcessedis a boolean flag you can later flip totrueor check in IF nodes.
This pattern comes up a lot when you are cleaning incoming data and preparing it for reports, invoices, or API calls.
Advanced Ways to Use the Set Node
1. Build clean API payloads
Before sending data to an external API, it is a good idea to build a clean, predictable payload. A Set node is perfect for this.
You can use it to:
- Rename fields to match the API’s schema
- Drop fields you do not want to send by enabling “Keep Only Set”
- Ensure all required fields are present and correctly typed
This reduces surprises, like accidentally sending internal fields or malformed values to external services.
2. Rename and combine fields
Need to adapt data from one service to another? The Set node is great for mapping fields. For example, if your previous node returns first_name and last_name, but the next service expects a single fullName field, you can create it with an expression:
{{ $json["first_name"] + " " + $json["last_name"] }}
You can keep or remove the original fields depending on your needs. This kind of small transformation keeps your workflows flexible without resorting to heavy custom code.
3. Create control flags for routing
Another common pattern is using the Set node to define boolean flags, like:
isHighPriorityshouldNotifyneedsReview
Later on, your IF or Switch nodes can read these flags and route items differently. It keeps your logic readable because you are essentially labeling items with clear, human friendly tags.
Troubleshooting Your Set Node
Things not working quite as expected? Here are a few quick checks.
- Fields not showing up? Make sure the Set node is actually connected to the right input, and that you clicked Execute on the workflow or node.
- Confused about what the node outputs? Open the node’s output preview or use the Debug panel to see exactly what fields are present.
- Expression errors? Double check your syntax and confirm that the fields you reference, like
$json["price"], actually exist on the incoming item. - Type issues? Remember that numbers in quotes are strings. Use helpers like
parseFloatorparseIntto convert them to real numbers when needed.
Best Practices for Using the Set Node
- Use clear, descriptive field names. Future you (and your teammates) will thank you when reading the workflow later.
- Change only what you need. Avoid renaming or overwriting fields unless you have a specific reason to. Less surprise means easier debugging.
- Give each Set node a single main purpose. For example, one node to normalize input, another to build an API payload, another to set flags. It keeps your workflow modular and easier to follow.
- Document tricky expressions. If you use a non-obvious expression, add a note on the node so others understand why it is there.
When the Set Node Is Not Enough
There are times when the Set node is not the best tool. If you need to:
- Perform complex calculations or multi step logic
- Iterate over arrays and create multiple new items
- Do heavy transformations on nested data structures
then a Function node or techniques like SplitInBatches or Item Lists might be a better fit.
For simple assignments though, the Set node is ideal. It is fast to configure, easy to read, and low risk compared to writing custom code.
Wrapping Up
The Set node is one of those small but essential building blocks in n8n. It helps you:
- Create and manage workflow variables
- Prepare clean payloads for APIs and other services
- Keep your data types and schemas consistent
Start with basic static values, like numbers, strings, and booleans, then gradually bring in expressions to make your workflows more dynamic and powerful.
Ready to Try It?
Open your n8n instance, drop in a Manual Trigger and a Set node, and recreate the simple example from earlier. Then experiment a bit:
- Change the values and types
- Reference fields from previous nodes
- Add timestamps and flags with expressions
The more comfortable you get with the Set node, the smoother the rest of your workflow building will feel.
If you want more n8n tips and automation ideas, subscribe to our newsletter for advanced recipes or grab a sample workflow you can import and run right away.
