Nodes/LF Nodes/Switch JSON
ComfyUI Node

Switch JSON

Flip between two JSON datasets with one boolean

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Switch JSON
  • on_true
  • on_false
  • ui_widget
  • json
  • json_list
booleanfalse

Here's a node that only makes sense inside the LF Nodes world, and that's fine - because that world is bigger than you think. SwitchJSON takes two JSON values and returns one of them based on a boolean. If you've never fed JSON through a Comfy graph, this looks pointless. If you've used LF's JSON nodes for wildcards, prompt datasets, or CivitAI metadata, it's suddenly the toggle that lets one workflow do two things.

The key context: LF Nodes is built around a particular JSON flavor - "Ketchup Lite-compatible" datasets with a nodes array structure that its widgets render as trees, tables, and charts. SwitchJSON operates on that whole payload, not just a string. So the practical use is selecting between two datasets: two prompt pools, two sets of resource metadata, two wildcard collections. Wire the output into an LF JSON node that consumes it and you've turned a boolean into "which dataset are we sampling from."

Mechanically it's a ternary like the other LF switches: on_true and on_false are JSON inputs, boolean decides. Outputs are json (single object) and json_list (list-typed). No lazy evaluation here - JSON is cheap, both sides get validated, and you just pick a branch.

The inputs you actually touch:

  • boolean - the condition, checkbox or wired from another node.
  • on_true / on_false - the two JSON datasets, typically from WriteJSON or an LF JSON node.

Where this shines is A/B testing a workflow without rebuilding it: keep dataset A and dataset B as separate WriteJSON blocks, switch between them, rerun. It pairs naturally with LF's GetValueFromJSON / GetRandomKeyFromJSON on the receiving end, and with UpdateUsageStatistics if you're tracking which dataset you actually used.

Installing LF Nodes - same pack, same steps:

  • ComfyUI Manager → search "LF Nodes" → install → restart, or
  • cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/comfyui-lf then restart.

Watch out for the two gotchas specific to this one. First, the JSON inputs expect LF's dataset format - a plain {"key": "value"} dict works for passthrough, but nodes that render widgets expect the nodes/children structure, so feed it from LF nodes if you want the pretty UI. Second, this repo is in legacy mode (frozen, migrated to lucafoscili/lf-nodes), so if you're loading a fresh workflow, prefer installing the new repo - the switch exists there too with the same name. No models to download, just the pack's standard dependencies.

Category✨ LF Nodes/Logic

Inputs (4)

NameTypeDefaultDescription
on_trueJSONValue to return if the boolean condition is true.
on_falseJSONValue to return if the boolean condition is false.
booleanBOOLEANfalseBoolean condition to switch between 'on_true' and 'on_false' values.
ui_widgetoptKUL_PROGRESSBAR[object Object]

Outputs (2)

NameTypeDescription
jsonJSON
json_listJSON