If you're building logic-based automations in n8n, one of the most essential nodes you'll encounter is the Switch node. Knowing how to use the Switch node correctly in n8n can save you hours of debugging and ensure your workflows remain clean, efficient, and straightforward. Whether you're building simple decision trees or complex flows with multiple outcomes, mastering this node is a must. In this guide, we’ll break down how it works, when to use it, and go through practical examples to help solidify your understanding.
What Is the Switch Node in n8n?
The Switch node is a control node used for decision making in workflows. It lets you route incoming data based on predefined conditions—think of it like an "if-else" or "switch-case" statement in programming.
Unlike the IF node, which handles only two branches (true or false), the Switch node can direct data into multiple paths depending on the value of a chosen property. This makes it ideal for handling scenarios where you need more than two conditional branches.
Why You Should Use the Switch Node
Here are some common reasons to use the Switch node in your workflows:
- Route data based on status codes or categories
- Control different email responses based on form inputs
- Trigger different APIs based on user role or data value
- Handle multiple webhook types from a single endpoint
Using a Switch node not only improves readability but also avoids nested IF nodes, which can quickly clutter your workflows.
Step-by-Step: How to Use Switch Node Correctly in n8n
Let’s walk through how to configure and use the Switch node effectively.
Step 1: Add and Connect the Switch Node
- Start by inserting the Switch node into your workflow.
- Connect it to a node that produces a value you want to evaluate (for example, a Webhook, Set, or HTTP Request node).
Step 2: Configure the Property to Evaluate
Inside the Switch node settings:
- Property Name: This is the path to the data you want to evaluate. For example,
{{$json["status"]}}will target thestatusfield. - Avoid inserting the expression block
{{}}directly here. Instead, write juststatusor use the expression editor to browse available fields.
Step 3: Define Switch Cases
Each case represents a condition you want to catch. You can add as many as needed.
Let’s say you have a webhook response with a type field that returns values like support, marketing, or sales. Your cases would look like:
| Case Value | Meaning |
|---|---|
| support | Route to customer support flow |
| marketing | Route to content marketing flow |
| sales | Route to sales outreach flow |
To set this up:
- Add “support” as the first case.
- Add separate branches for “marketing” and “sales”.
- Always assign an output branch under each case.
You can also set a default case for unmatched values, which is good practice for error handling or logging unexpected inputs.
Step 4: Connect Outputs to the Right Nodes
Each case in the Switch node has a numbered output (e.g., Output 0, Output 1). These correspond to cases in the order they’re listed. Simply connect these to other nodes that handle different actions.
For instance:
- Output 0 (support) → Send Email node to support team
- Output 1 (marketing) → Create task in marketing board using n8n’s ClickUp integration
- Output 2 (sales) → Start Salesforce CRM automation using this Salesforce setup
Real-World Use Case: Multi-Channel Support Routing
Imagine you run a support team and use Typeform to collect inquiries. The inquiries come with a field called issue_type, which can be "bug", "feature request", or "billing".
By using the Switch node, you can automate routing like this:
- Use a Webhook to receive the Typeform submission.
- Set node extracts the
issue_type. - The Switch node evaluates
issue_type. - Each output links to a different Slack channel using the Slack Integration or sends an email to the relevant department.
This keeps your workflow clean and helps teams handle inquiries efficiently.
Best Practices for Using the Switch Node
Use Exact Value Matching
Switch cases are always matched exactly unless you use expressions. If you want to handle ranges or partial text, you’ll need to pair it with a Function or IF node.
Label Your Outputs
To keep things readable, label each output using Notes or meaningful node names right after the switch node.
Add a Catch-All Default Case
Always add a default case to handle unanticipated values. This avoids "dead ends" in your workflow and is helpful for logging or error-catching steps.
Avoid Nesting Switches Without Obvious Logic
Nesting multiple Switch nodes can make your workflows confusing. If needed, group logical branches using sub-workflows or SplitInBatches nodes to manage complexity.
Example: Decision-Based Email Response
Suppose you operate an online course that receives student feedback.
- If feedback = "positive", you send a thank-you email.
- If feedback = "neutral", you ask for suggestions.
- If feedback = "negative", you notify the support team.
How to build this:
- Get feedback value via webhook or form.
- Use a Switch node on
{{$json["feedback"]}}. - Create three cases: positive, neutral, negative.
- Connect each to the appropriate Email or Slack notification node.
This keeps your flow modular and easy to modify as responses evolve.
When Not to Use a Switch Node
Sometimes, a Function node or IF node is better.
Use a Function when:
- You need complex comparisons (e.g., value > 100).
- You want to transform input data before routing it.
Use an IF node when:
- You have only two paths to check.
For multi-option routing, though, Switch is your go-to.
Common Issues and How to Avoid Them
- Property Name not recognized: Make sure you’re referencing the correct data path without curly braces.
- Wrong output path: Remember, output numbers match the case order.
- All cases skipped: Add a default case to catch unexpected matches.
FAQ
How many cases can I define in a Switch node?
You can define as many cases as you need. However, for very large numbers of conditions, consider using a Function node for better performance.
Can I use partial matches or regex in a Switch node?
No, the Switch node only matches exact values. For advanced logic like regex, you'll need to use a Function node or pre-process the data before the switch.
How do I add a default case in the Switch node?
There’s a toggle called “Use Default Case” at the bottom of the Switch node. Enable it and connect that output to your fallback logic, like logging or error handling.
Is the Switch node better than the IF node?
It depends. Use the IF node for binary logic (true/false). Use the Switch node when you need to handle three or more possibilities.
Can a Switch node evaluate multiple properties at once?
No, it can evaluate only one property at a time. If you need to check multiple fields, chain Switch or IF nodes, or use a Function node for combined logic.
By understanding how to use the Switch node correctly in n8n, you’re one step closer to building smarter, more dynamic workflows. It’s a small node with big potential—just make sure to apply it with a thoughtful structure and solid data mapping for maximum efficiency.
Copy-paste templates.
Beginner friendly.