ComfyUI Node

String Switch

A two-way gate for any value, with sensible defaults baked in

By ethanfel·Created 7 months ago·Updated 2 months ago· 2
String Switch
  • on_true
  • on_false
  • result
conditiontrue
default_true
default_false

String Switch is the classic A/B switch shape: a boolean decides which of two values comes out the other end. What makes this one pleasant instead of annoying is the fallback behavior - you can leave both sides unwired and just type the two outcomes as widget strings, which covers the 90% case of "switch between prompt A and prompt B without building three nodes."

The inputs

  • condition (BOOLEAN, default true) - the switch. Wire it from a boolean primitive, a comparison node, or a JSON loader value.
  • on_true / on_false - optional, typed *, so they accept any type: strings, ints, images, latents, whatever. When one is connected, it wins.
  • default_true / default_false (STRING) - the fallback widget values used when the corresponding input isn't connected.

The precedence is exactly what you'd hope: a connected input beats its widget default. So you can build a workflow where the toggle lives in the widgets most of the time, and the day you want the choice driven by data, you wire an input and it takes over without touching the defaults. That's the first-non-null pattern from ComfyUI's switch-node family, and this node implements it cleanly.

The output

A single result output, typed * to match whatever you routed through it. Feed it into a text encoder, a save filename, or further downstream plumbing.

Where people get caught: because both inputs are *, the node won't police that you're switching between same-typed things. Swapping between a STRING and an IMAGE through the same socket is legal but almost never what you want - downstream nodes will reject one branch at link time. Keep both sides the same type unless you're doing something genuinely weird.

Also note the defaults are strings. If you want to switch between two integers, either wire two int primitives in, or accept that you'll get the numbers back as text.

Install

Part of ComfyUI-JSON-Dynamic. ComfyUI Manager → search JSON Dynamic Loader, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ethanfel/ComfyUI-JSON-Dynamic.git
# restart ComfyUI

No dependencies beyond ComfyUI core.

Verdict

If your workflow already has a boolean to act on - "is this a close-up shot?" from a JSON loader, a masked/unmasked toggle - String Switch is the clean two-way gate for it. For three-or-more-way selection you'll want a proper multi-switch node instead; this one is deliberately just an on/off valve with good defaults.

CategoryJSON Dynamic/string

Inputs (5)

NameTypeDefaultDescription
conditionBOOLEANtrue
on_trueopt*
on_falseopt*
default_trueoptSTRING
default_falseoptSTRING

Outputs (1)

NameTypeDescription
result*