Reference · Tools

Switch

Routes items to multiple output branches based on configurable rules or expressions.

Action Core Nodes v1

The Switch node evaluates items against routing rules and sends each one down the first branch that matches, with anything unmatched going to a fallback output. It supports up to ten branches and needs no credentials. A typical build is routing support tickets to different handlers by category.

Node type
Action
Parameters
6
Outputs
Output 0, Output 1, Output 2, Output 3, Output 4, Output 5, Output 6, Output 7, Output 8, Output 9, Fallback
Credentials
None required

Switch

Route to multiple outputs by value

Overview

Routes workflow items to multiple output branches based on configurable rules or expressions. Supports complex business logic with many possible paths.

Category: Core Nodes
Tool Name: switch
Version: 1

Appearance: Icon: switch | Color: #f97316

Node Type

Action — processes input items and produces output

Input / Output

DirectionPort(s)
InputInput
OutputOutput 0, Output 1, Output 2, Output 3, Output 4, Output 5, Output 6, Output 7, Output 8, Output 9, Fallback

Credentials

This tool does not require any credentials.

Parameters

ParameterTypeRequiredDefaultDescription
ModeoptionsYesrulesRules Mode: Define matching conditions for each output. Expression Mode: Use an expression that returns an output index (0-9).
Options: rules, expression
Output Index ExpressionstringYes{{ $json.outputIndex }}Expression that evaluates to an output index (0-9). Example: {{ $json.tier === ‘gold’ ? 0 : ($json.tier === ‘silver’ ? 1 : 2) }} (shown when Mode is expression)
Routing RulesfixedCollectionNo{}Define conditions for routing items to different outputs. (shown when Mode is rules)
— Output IndexnumberNo0Which output (0-9) to route matching items to.
— Output NamestringNoOptional friendly name for this output (for documentation purposes).
— Combine Conditions WithoptionsNoandHow to combine multiple conditions for this rule.
Options: and (all conditions must match), or (any condition may match)
— ConditionsfixedCollectionNo{}The conditions this rule evaluates.
— — FieldstringNo{{ $json.field }}Field to evaluate. Use expression syntax: {{ $json.fieldName }} or {{ $json.nested.field }}
— — Data TypeoptionsNostringThe data type of the field being compared.
Options: string, number, boolean, dateTime, array, object
— — Operation (operation)optionsNoequalsString comparison operation to perform. (shown when Data Type is string)
Options: equals, notEquals, contains, notContains, startsWith, endsWith, matchesRegex, isEmpty, isNotEmpty, exists, notExists
— — Operation (operation)optionsNoequalsNumber comparison operation to perform. (shown when Data Type is number)
Options: equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, exists, notExists
— — Operation (operation)optionsNoisTrueBoolean comparison operation to perform. (shown when Data Type is boolean)
Options: isTrue, isFalse, equals, exists, notExists
— — Operation (operation)optionsNoequalsDate/Time comparison operation to perform. (shown when Data Type is dateTime)
Options: equals, notEquals, greaterThan (after), greaterThanOrEqual (after or equal), lessThan (before), lessThanOrEqual (before or equal), exists, notExists
— — Operation (operation)optionsNoarrayContainsArray comparison operation to perform. (shown when Data Type is array)
Options: arrayContains, arrayNotContains, arrayLengthEquals, arrayLengthGreaterThan, arrayLengthLessThan, isEmpty, isNotEmpty, exists, notExists
— — Operation (operation)optionsNohasKeyObject comparison operation to perform. (shown when Data Type is object)
Options: hasKey, notHasKey, isEmpty, isNotEmpty, exists, notExists
— — ValuestringNoValue to compare against. Supports expressions: {{ $json.otherField }} (hidden when Operation is exists, notExists, isEmpty, isNotEmpty, isTrue, isFalse, matchesRegex)
— — Regex PatternstringNoRegular expression pattern to match against. (shown when Operation is matchesRegex)
Fallback BehavioroptionsNooutputWhat to do with items that don’t match any rule or have an invalid expression result.
Options: output (send to the Fallback output), drop (discard the item entirely), error (create an error item)
Include Match InfobooleanNofalseAdd _switchMatch metadata to output items showing which rule/output they matched.
Max ConcurrencynumberNo50Maximum items to process concurrently.

Output Data

Each input item leaves through exactly one output. The item JSON passes through unchanged and binary data is forwarded; the node only adds a property when Include Match Info is on.

  • Rules Mode — rules are evaluated in the order you list them and the first match wins, so put the most specific rule first. The item goes to that rule’s Output Index. A rule with no conditions is skipped.
  • Expression Mode — the item goes to the output whose index the expression returns. A result that is not a whole number between 0 and 9 counts as no match.
  • No match — Fallback Behavior decides. output sends the item to the Fallback output; drop discards it, so it leaves the workflow and reaches no output at all; error turns it into an item error.

With Include Match Info on, each output item carries:

{
  "_switchMatch": {
    "mode": "rules",
    "outputIndex": 0,
    "matchReason": "Gold Tier",
    "matchedAt": 1765432100000,
    "ruleName": "Gold Tier"
  }
}
  • matchReason is the matching rule’s Output Name when it has one, otherwise rule_{position}_output_{index}. In Expression Mode it reads expression_result:{index}, or expression_invalid when the expression did not produce a usable index. An item that fell through to the fallback output reads fallback.
  • ruleName is added in Rules Mode only, and is null when the matching rule has no Output Name.
  • Fallback is also the error output. With error handling set to continue (the default), an item that fails is routed to Fallback carrying an _error object, so check for it before treating that branch as unmatched traffic.

Reference the metadata downstream by expression, e.g. {{ $json._switchMatch.outputIndex }}.

Usage Examples

  • switch based on status field
  • route orders to different handlers by type
  • dispatch to team based on priority
  • categorize items into buckets
  • direct traffic based on region

Example Configuration

Route customers to one branch per subscription tier, with everything else going to the fallback output:

{
  "type": "switch",
  "parameters": {
    "mode": "rules",
    "fallbackBehavior": "output",
    "includeMatchInfo": true,
    "rules": {
      "rule": [
        {
          "outputIndex": 0,
          "outputName": "Gold Tier",
          "combineOperation": "and",
          "conditions": {
            "condition": [
              {
                "field": "{{ $json.subscription.tier }}",
                "dataType": "string",
                "operation": "equals",
                "value": "gold"
              }
            ]
          }
        },
        {
          "outputIndex": 1,
          "outputName": "Silver Tier",
          "combineOperation": "and",
          "conditions": {
            "condition": [
              {
                "field": "{{ $json.subscription.tier }}",
                "dataType": "string",
                "operation": "equals",
                "value": "silver"
              }
            ]
          }
        }
      ]
    }
  }
}

Send high-value or long-standing customers down a single VIP branch — any one condition is enough:

{
  "type": "switch",
  "parameters": {
    "mode": "rules",
    "fallbackBehavior": "output",
    "rules": {
      "rule": [
        {
          "outputIndex": 0,
          "outputName": "VIP Processing",
          "combineOperation": "or",
          "conditions": {
            "condition": [
              {
                "field": "{{ $json.vipStatus }}",
                "dataType": "boolean",
                "operation": "isTrue"
              },
              {
                "field": "{{ $json.purchaseAmount }}",
                "dataType": "number",
                "operation": "greaterThanOrEqual",
                "value": "1000"
              }
            ]
          }
        }
      ]
    }
  }
}

Pick the output branch with an expression instead of rules:

{
  "type": "switch",
  "parameters": {
    "mode": "expression",
    "outputExpression": "{{ $json.priority === 'high' ? 0 : ($json.priority === 'medium' ? 1 : 2) }}",
    "fallbackBehavior": "output",
    "includeMatchInfo": true
  }
}

Error Handling

ModeBehavior
stopHalts workflow on first error
continueSkips failed items, passes successful ones through
errorPortRoutes failed items to Error output port

Tips

Evaluates input data against multiple routing rules and directs items to the first matching output branch. Use when items need to be categorized into 3+ distinct paths based on field values or conditions. Produces items on the output branch whose rule matched first, with unmatched items going to a fallback output.

Key Usage Notes

  • Rules vs Expression Mode: Use rules mode for simple condition-based routing. Use expression mode for complex calculated routing or when you need dynamic output selection.
  • Output Indexing: Outputs are numbered 0-9. Ensure your rules or expressions return values within this range.
  • Fallback Behavior: Always consider what should happen to items that don’t match any conditions. Use “drop” carefully as items will be lost from the workflow.
  • Match Info: Enable includeMatchInfo when debugging or when downstream nodes need to know which rule was matched.

Frequently asked questions

When should I use Switch instead of If?

When there are three or more distinct paths. If handles a binary decision; Switch is built for categorising into several outputs without chaining Ifs.

What happens to items that match nothing?

They go to the Fallback output rather than being dropped, so nothing disappears silently.

Rules or expression mode?

Rules mode for straightforward condition-based routing. Expression mode when the branch is computed rather than matched — for example deriving the output index from a field.

What if an item matches several rules?

It goes down the first matching branch only. Order your rules from most specific to most general.

Build with the Switch node

Drop it into a workflow, wire it to an agent, or call it on a schedule.

Open BusyBot

Last updated . Spotted something wrong? Tell us.