Nodes/comfyui-json-nodes/JSON Object Merge
ComfyUI Node

JSON Object Merge

Combine fragments into one payload without hand-writing JSON

By ollieedgeley·Created 6 months ago·Updated 6 months ago· 3
JSON Object Merge
  • objects
  • JSON_TEXT
duplicate_key_policyerror
pretty_printtrue

If JSON Field is the brick, JSON Object Merge is the mortar. It takes two or more JSON object strings, smashes them into one object, and hands you the result as a string you can send anywhere - an API endpoint, a webhook, another node that happens to want structured data. ComfyUI's stock toolset has no clean answer for "I have several small JSON fragments, now make one payload," and this is that answer.

How it works

The node uses autogrow inputs, which is the modern ComfyUI way of saying "the node grows more input sockets as you connect things." You start with a couple of json_object_1 / json_object_2 inputs and ComfyUI adds more as needed, up to 64. Each connected input has to contain a JSON object string. They're merged in numeric order - json_object_1, json_object_2, and so on - and nested objects are deep-merged, so two fragments that each define camera.lens combine into one camera rather than one clobbering the other.

That deep merge is the detail that makes this worth reaching for over a text node: if {"camera": {"lens": 85}} and {"camera": {"iso": 100}} meet, you get {"camera": {"lens": 85, "iso": 100}}. That's real merging, not concatenation.

Inputs and output

  • objects - the autogrow JSON object inputs. Each must be a valid JSON object; a non-object or invalid JSON raises a readable error.
  • duplicate_key_policy - error (default), overwrite, or keep_first. Controls what happens when two inputs define the same key.
  • pretty_print - on by default; gives you indented output that's easy to eyeball in the UI.

Output is JSON_TEXT, a STRING with the merged object.

The duplicate-key decision is the real gotcha

The default policy is error, and it's strict about it: two fragments both setting name and the node fails with something like Duplicate key 'name' in object 1 and object 2. That's a great safety net while you're building - it catches the case where a later field is silently clobbering an earlier one. But it will also stop a workflow that genuinely wants a later value to win. When that happens, you've got two sane options:

  • overwrite - later input wins. Right for "this fragment is the override."
  • keep_first - first input wins. Right for "defaults, with earlier values taking priority."

There's no wrong answer, just decide deliberately. If you find yourself flipping it constantly, the pack exposes a default under ComfyUI Settings → JSON Nodes → Default duplicate key policy, which applies to newly created nodes (existing workflows keep their saved values).

Installing it

It ships in the comfyui-json-nodes pack, so one install gets you all five nodes. Easiest: ComfyUI Manager, search comfyui-json-nodes. Or by hand:

cd <ComfyUI>/custom_nodes
git clone https://github.com/olliethomas1992/comfyui-json-nodes

Restart ComfyUI; everything lands under utils/json. No extra Python dependencies, no model files - the pack's requirements.txt is intentionally empty.

Common issues

Beyond duplicate-key errors, the thing people hit is feeding it something that isn't a JSON object - a bare string or a JSON array parses fine but fails the object check, with a readable error pointing at which input. And remember the merge order matters for overwrite: inputs are merged in socket order, so which fragment wins is determined by where it sits on the node, not by how you phrased it.

Categoryutils/json

Inputs (3)

NameTypeDefaultDescription
objectsCOMFY_AUTOGROW_V3
duplicate_key_policyCOMBOerrorWhat to do when multiple inputs contain the same key: error (reject), overwrite (last wins), or keep_first (first wins).
pretty_printBOOLEANtrue

Outputs (1)

NameTypeDescription
JSON_TEXTSTRING