Nodes/ZMG PLUGIN/JSON构建器
ComfyUI Node

JSON构建器

Build a JSON payload without touching a keyboard's curly braces

By fq393·Created 2 years ago·Updated 7 months ago· 8
JSON构建器
  • passthrough
  • json_string
  • formatted_json
  • passthrough
key1
value1
key2
value2
key3
value3
key4
value4
key5
value5
merge_json
merge_to_key
pretty_formattrue
sort_keysfalse

If you're calling APIs from a workflow (say, with the pack's API Request Node), you eventually need to construct a JSON body. That's what this node does, and it makes it genuinely painless: five key/value pairs, plus the ability to merge in a whole JSON object, and it sorts out types for you. No json.dumps in your head required.

How it works

You type keys and values into plain text boxes and it assembles them into a JSON object. The clever part is the type inference: values that look like numbers become numbers, true/false become booleans, null becomes null, and anything that parses as a JSON object or array ({...} or [...]) gets embedded as a real nested structure. A value wrapped in quotes stays a string. So count → 3 produces "count": 3, not "count": "3", which is exactly where beginners get burned with naive string-concatenation approaches.

There's also a merge_json field: paste in an existing JSON object and it merges into the result - either at the root, or under a specific key you name in merge_to_key. So you can hand-build the parts you care about and merge in a pre-made blob from elsewhere in the graph.

Inputs that matter

  • key1–key5 / value1–value5 - five pairs of key and value. Keys are single-line; values are multiline, which matters for long strings. Empty keys are skipped, so you don't have to fill all five.
  • merge_json - a JSON object string to merge in.
  • merge_to_key - if set, the merged object lands under this key (existing dicts are merged into; non-dicts are replaced). Empty means merge at the root.
  • pretty_format - on (default) gives you indented JSON; off gives you compact, which is what most APIs want as a payload.
  • sort_keys - alphabetize keys. Mostly useful when you're diffing outputs.
  • passthrough - a wildcard input that comes back unchanged as an output, handy for keeping data flowing while the JSON is built.

Outputs

json_string (the JSON, compact or pretty per your setting) and formatted_json (always pretty-printed), plus passthrough. Feed json_string into an API node's request_params, a text saver, or a JSON Parser for round-trips.

One honest note: it's not a full templating engine. It has no variables or references - every value is a literal at build time. If you need dynamic values, wire text nodes in upstream or generate the JSON elsewhere. For static payloads and config blocks, it's the right tool.

Installing

Part of the ZMG pack. ComfyUI Manager → search "ZMG" / "ComfyUI-ZMG-Nodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/vanche1212/ComfyUI-ZMG-Nodes
cd ComfyUI-ZMG-Nodes
pip install -r requirements.txt

Restart ComfyUI; it shows up under ZMGNodes/data. No extra dependencies - it's pure Python standard library. And if your JSON ever comes out wrong, the debug output in the console walks through the merge step by step, which beats guessing.

CategoryZMGNodes/data

Inputs (15)

NameTypeDefaultDescription
key1optSTRING
value1optSTRING
key2optSTRING
value2optSTRING
key3optSTRING
value3optSTRING
key4optSTRING
value4optSTRING
key5optSTRING
value5optSTRING
merge_jsonoptSTRING
merge_to_keyoptSTRING
pretty_formatoptBOOLEANtrue
sort_keysoptBOOLEANfalse
passthroughopt*

Outputs (3)

NameTypeDescription
json_stringSTRING
formatted_jsonSTRING
passthrough*