Skip to content

A switch compares its value; it does not evaluate it

Despite the parameter's name, a switch gateway runs no expression engine. The value is matched against each branch as it stands.

The rule

Normative: this is the rule
  1. A switch gateway MUST NOT evaluate its expression.
  2. The value MUST be compared unchanged against each branch's value, in declaration order.
  3. A branch MUST match if and only if the two values are equal as the conventions define equal values, which is JSON Schema's const equality, with no conversion between types.
  4. The first matching branch MUST be the sole active branch.
  5. The gateway MUST report that branch's name as active.
  6. Where no branch matches, the branch named by default_branch MUST be active.
  7. Where no branch matches and no usable default is named, the node MUST fail.

What it means

The parameter is named expression, but no expression engine ever sees it. A value that happens to look like a query — a JSONPath-shaped string, say — is still just a string, compared for equality against each branch's own value in the order the branches are declared. There is no conversion either: a value and a branch of different JSON types never match, even where a conversion would make them equal.

Only the first branch to match becomes active, and its declared name is what the gateway reports. Nothing matching falls through to the configured default branch; nothing matching and no usable default fails the node outright.

Example

A value shaped exactly like a JSONPath query, matched against a branch whose own configured value is that same literal string:

The expression and the branches it is compared against
{
  "expression": "$.user.role",
  "default_branch": "default",
  "branches": [
    { "name": "Admin", "value": "admin" },
    { "name": "Literal", "value": "$.user.role" }
  ]
}
The active branchactive
["Literal"]

The same strictness rules out a type match that a looser comparison would allow:

A string expression against a branch whose value is the integer 1
{ "expression": "1", "default_branch": "Fallback", "branches": [{ "name": "IntOne", "value": 1 }] }
The active branchactive
["Fallback"]

"1" and 1 are equal after conversion but not of the same type, so the comparison misses and the configured default branch, Fallback, is what activates.

Equality is JSON Schema's, not the host language's. Two numbers with the same value are equal however they were written, and two objects are equal whatever order their members arrive in:

A number and an object, against branches written differently
{
  "expression": {"role": "admin", "level": 1.0},
  "default_branch": "Fallback",
  "branches": [{ "name": "Admin", "value": {"level": 1, "role": "admin"} }]
}
The active branchactive
["Admin"]

Why

Recorded under OPEN-25, OPEN-29.

Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0 · LANG-27 · changed in spec 1.0