JsonExtractBoolean
Turn a value in a JSON blob into a toggle
- BOOLEAN
ComfyUI graphs like to be controlled by a single source of truth sitting at the top - a note, a config string, a TOML prompt file's exports block. The moment that source is JSON, you need a way to pull individual fields out of it, and that's the entire job of the JsonExtract* family in this pack. JsonExtractBoolean is the one that hands you a BOOLEAN you can wire into a toggle input: enable a hires-fix pass, switch a branch on, gate a LoRA, whatever your graph has converted to an input.
It's a small node and it's genuinely useful, because "read a flag out of a config" is otherwise a manual step you redo every run.
How it works
def extract(self, json_text: str, path: str, default: bool):
r = json.loads(json_text)
for key in path.split("."):
if key not in r:
return (default,)
r = r[key]
if isinstance(r, str):
return (r == "True" or r == "true",)
else:
return (not not r,)
Three things fall out of that:
pathis dot-separated and walks dict keys, sohires.enabledlooks inside{"hires": {"enabled": true}}. Lists are not indexed - there's no[0]syntax.- A missing key returns
default, which is the whole reasondefaultexists as a required input. No exception, no red node. - Strings get compared literally against
"True"and"true". So"yes","1","TRUE"all read asFalse. Everything non-string falls through to Python truthiness:0,"",[]and{}areFalse, anything else isTrue.
That last part matters in practice because JSON written by hand and JSON written by a tool look different. If a config value comes out inverted, print it and check whether it's the boolean true or the string "true".
Inputs and outputs
json_text - the blob, wired in from wherever your config lives (this pack's PromptDecode has a JSON Exports output that plugs in directly). path - the dotted route to the value. default - what you get when the path doesn't resolve. One BOOLEAN output.
Siblings do the same thing at other types: JsonExtractInt, JsonExtractFloat, JsonExtractString. Same three inputs, same dotted path, different output type.
Install
Manager search for the pack name, or:
cd ComfyUI/custom_nodes
git clone https://github.com/morino-kumasan/comfyui-toml-prompt
restart ComfyUI. No pip step - requirements.txt is empty, this is stdlib json plus ComfyUI. The pack's README still documents an SSH clone of its old comfyui-utils name; use the HTTPS URL above.
Where people get burned
Invalid JSON raises. The json.loads call is not guarded - only missing paths fall back to the default. A trailing comma or a stray smart quote and the node throws instead of quietly using your default. If a node that "should just return the default" is erroring, your JSON is malformed, not your path.
A path that silently diverges from your config. Rename a key in the TOML and this node keeps returning the default forever, with no warning. When a flag "isn't taking effect," check the path before anything else.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| json_text | STRING | — | |
| path | STRING | period separated path to json value | |
| default | BOOLEAN | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| BOOLEAN | BOOLEAN | BOOLEAN. |