JSON构建器
Build a JSON payload without touching a keyboard's curly braces
- passthrough
- json_string
- formatted_json
- passthrough
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.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| key1opt | STRING | — | |
| value1opt | STRING | — | |
| key2opt | STRING | — | |
| value2opt | STRING | — | |
| key3opt | STRING | — | |
| value3opt | STRING | — | |
| key4opt | STRING | — | |
| value4opt | STRING | — | |
| key5opt | STRING | — | |
| value5opt | STRING | — | |
| merge_jsonopt | STRING | — | |
| merge_to_keyopt | STRING | — | |
| pretty_formatopt | BOOLEAN | true | — |
| sort_keysopt | BOOLEAN | false | — |
| passthroughopt | * | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| json_string | STRING | — |
| formatted_json | STRING | — |
| passthrough | * | — |