Nodes/ComfyUI-YogurtNodes/JsonDeepCopy (Yogurt Nodes)
ComfyUI Node

JsonDeepCopy (Yogurt Nodes)

Copy a JSON object so mutating it doesn't wreck the original

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
JsonDeepCopy (Yogurt Nodes)
  • json_data
  • copied_json

In a normal script, you copy a dict and move on. In a node graph, the same object can flow to five different nodes at once - and if one of them mutates it, the other four suddenly see your changes. JsonDeepCopy is the insurance policy: take a JSON object, get back a fully independent copy, and modify that one without touching the original.

It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), part of a whole family of JSON utilities (parse, stringify, merge, get/set path…). If you're doing any serious config-driven work - building API payloads, feeding structured data to an LLM node, juggling metadata - this is the safety net.

How it works

The mechanism is Python's copy.deepcopy, which recurses through the entire structure - nested dicts, lists, arrays - and duplicates every level. That's what "deep" means here: not just the outer dict, but every nested piece of it. You get copied_json back, which is a distinct object with the same contents. Change it all you want; the input is untouched.

Why does that matter in ComfyUI specifically? Because nodes pass references, not copies. Two branches fed from the same JSON output share one underlying object. If JsonSetPath modifies in place (it has a copy_data option for exactly this reason, defaulting to on), a shallow share can leak mutations across your whole graph. A DeepCopy between the source and a mutating node severs that link cleanly.

Inputs that matter

  • json_data - any JSON-compatible object. Dicts, lists, and mixes thereof. It's an any-type input, so you can't hook it up wrong.

Output: copied_json, an independent copy.

Install

The pack-wide routine - ComfyUI Manager (search "YogurtNodes") or:

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

Restart, find it under Yogurt Nodes / Logic. Pure Python, zero extra dependencies.

Troubleshooting

There's genuinely little to go wrong with a deep copy, but two things are worth saying:

  • Deep copy of non-JSON objects. The node is named for JSON, but deepcopy works on any Python object. If you feed it something exotic - a tensor, a custom class - it'll still copy it, but the result may not be what a downstream node expects. Keep it to JSON-shaped data and you're safe.
  • When you don't need it. If a node already returns a fresh object (parse and stringify do), copying first is just wasted work. Use DeepCopy when you're reusing an object that something downstream mutates - the classic case being SetPath's copy_data toggle vs. a shared source.

The rule of thumb: put one of these between a JSON object and anything that modifies it, and your branches stop stomping on each other. Cheap, invisible, and the exact kind of thing you only notice after it saves you an hour of debugging.

CategoryYogurtNodes/Logic

Inputs (1)

NameTypeDefaultDescription
json_data*JSON object to copy

Outputs (1)

NameTypeDescription
copied_json*