Nodes/Quality of Life Nodes for ComfyUI/JSON Chain Generate (Soze)
ComfyUI Node

JSON Chain Generate (Soze)

Where the JSON chain ends — serializing your payload

By SozeInc·Created 2 years ago·Updated 8 days ago· 10
JSON Chain Generate (Soze)
  • chain_in
  • json
  • status
prettytrue
indent2
sort_keysfalse

Every chain of Soze JSON pair nodes ends here. JSON Chain Generate (Soze) takes the JSON_PAIRS chain you've been building - the accumulated (key, value) tuples - and serializes it into an actual JSON string, which is the thing you can pipe into an API node, write to a file, or hand to anything else that wants text. Build the structure with the pair nodes; this is the terminal that makes it real.

It's the node that separates "I've assembled a chain" from "I have a payload." The output is a proper, validated JSON string with correct quoting and escaping - no more fixing broken hand-typed JSON, no more wondering whether your " matched. You could honestly stop reading after this sentence: build pairs, take the last pair node's chain_out and wire it into chain_in here, then read the json output. The rest is polish.

How it works

The chain is collapsed into a dict - and there's one behavior worth knowing: duplicate keys are allowed, and the last one wins, standard dict semantics. The node doesn't silently drop the earlier value; it counts them and reports the overwrite in its status output, so you can spot the bug. Then it serializes with json.dumps and returns the text plus a status string like OK: 5 key(s), 123 chars.

Inputs and outputs

  • chain_in - required JSON_PAIRS. Connect the last pair node's chain_out here.
  • pretty - optional, default true. Pretty-print with the indent below. Off produces compact JSON (no whitespace) - what you usually want for API bodies and file size.
  • indent - optional INT, default 2, used only when pretty is on.
  • sort_keys - optional BOOLEAN, default false. Sort keys alphabetically - nice for diffing two payloads, annoying if key order matters to the API.

Outputs are json (the STRING) and status (a STRING summary you can watch in the node or wire to a text display).

String Pair("name","Alice") → Int Pair("age",30) → JSON Generate (pretty=off)

{"name":"Alice","age":30}.

Installing it

Part of the Soze pack:

cd ComfyUI/custom_nodes
git clone https://github.com/SozeInc/ComfyUI_Soze.git
pip install -r ComfyUI_Soze/requirements.txt

Restart ComfyUI, or search ComfyUI_Soze in ComfyUI Manager.

Gotchas

Three things. First, if serialization fails - say a value that can't be JSON-encoded sneaks in via a wildcard slot - it returns an empty string and an ERROR: status rather than crashing ComfyUI; check status, not just the payload. Second, pretty output with a big image or audio payload gets big; flip pretty off for anything you're sending over the wire. Third, sort_keys interacts with the duplicate-key rule: sorted output makes duplicates easier to spot, which is a decent debugging trick on its own.

CategorySoze Nodes/JSON

Inputs (4)

NameTypeDefaultDescription
chain_inJSON_PAIRS
prettyoptBOOLEANtruePretty-print with the given indent. If False, output is compact.
indentoptINT20–10
sort_keysoptBOOLEANfalse

Outputs (2)

NameTypeDescription
jsonSTRING
statusSTRING