JsonExtractInt
Steps, seeds and clip skip from a config blob
- INT
Here's the pattern this node exists for, straight out of the pack's own sample workflows: a TOML prompt file holds an [_exports] block with steps, cfg, clip, model and friends. PromptDecode decodes it and emits those exports as JSON. Then a chain of JsonExtract* nodes reads individual fields off that JSON and drives the loader and sampler. Change the TOML, and the whole generation changes - steps, clip skip, and which checkpoint loads.
JsonExtractInt is the integer reader in that chain. It's a boring node doing a necessary job: pulling an INT out of a text blob.
How it works
def extract(self, json_text: str, path: str, default: int):
r = json.loads(json_text)
for key in path.split("."):
if key not in r:
return (default,)
r = r[key]
return (int(r),)
path is dot-separated and walks dictionary keys - sampling.steps reaches into {"sampling": {"steps": 20}}. If any key along the way is missing you get default back, quietly, with no error. If the path resolves, the value goes through int().
Two consequences worth internalising:
- The value has to be numeric-coercible. A JSON string
"20"becomes20, which is exactly what you want here, because the exports from a TOML file arrive as strings. But"twenty"raises aValueError- a present value that can't be coerced is an error, unlike a missing path, which is a default. - Floats truncate.
int(20.9)is20, toward zero. For steps that's fine; for anything where the fractional part is meaningful, useJsonExtractFloat.
Inputs and outputs
json_text (the blob), path (dotted route, tooltip: "period separated path to json value"), default (an INT, used when the path doesn't resolve). One INT output. The pack's siblings - JsonExtractString, JsonExtractFloat, JsonExtractBoolean - are identical in shape with different output types, so the four of them together will unpack a whole config dict.
Install
Manager search for the pack, or:
cd ComfyUI/custom_nodes
git clone https://github.com/morino-kumasan/comfyui-toml-prompt
restart ComfyUI. Nothing to install: requirements.txt is empty and the parsing is stdlib json. Ignore the README's install block if you read it - it still clones the pack's old comfyui-utils name over SSH.
Where people get burned
A quiet default hides a broken config. Because a missing key returns default instead of erroring, a typo in path means you silently generate at your default steps forever. When output stops responding to your config edits, this is the first place to look - check the path character by character.
Numbers that are actually strings. If your JSON has "steps": "20 steps" (yes, people write configs like that), you get a ValueError at run time. That's the good failure mode, but it lands on the node, not the file, so read the traceback rather than assuming the JSON is broken.
Clip skip expects a negative. stop_at_clip_layer on the pack's checkpoint loader wants -1/-2; pulling a positive 2 out of a config and feeding it there does nothing, because the loader only calls CLIPSetLastLayer for negative values.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| json_text | STRING | — | |
| path | STRING | period separated path to json value | |
| default | INT | -9223372036854776000–9223372036854776000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | INT. |