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

JsonUnflatten (Yogurt Nodes)

Reassemble flat keys into the nested JSON you actually wanted

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
JsonUnflatten (Yogurt Nodes)
  • flat_json
  • nested_json
separator.
auto_detect_arraystrue

JsonFlatten is the "make it flat so I can work with it" node; JsonUnflatten is the "now give it back" half. Feed it {"settings.model": "xl", "settings.steps": 20, "items.0.name": "ada"} and it rebuilds the nested object - {"settings": {"model": "xl", "steps": 20}, "items": [{"name": "ada"}]} - complete with arrays where the keys imply them.

It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), the round-trip partner to Flatten. Where that round trip matters: you flatten a config so an LLM can see/edit it as a linear list of key = value lines, then unflatten the edited version back into structured form for an API call.

How it works

It splits each flat key on separator (default .) and rebuilds the hierarchy, nesting dicts along each path. The clever bit is auto_detect_arrays (default on): a segment that looks like an integer index - items.0, items.1 - becomes an array element instead of a dict key. So items.0.name builds a list, not a dict with a key literally named "0". Turn auto_detect_arrays off and every segment stays a dict key, which is what you want when your keys are genuinely numeric-named.

Two things to keep straight so the round trip survives:

  • The separator must match what Flatten used. Flatten with . and unflatten with > and your keys come back looking like "settings>model" - a wrong separator quietly produces garbage that looks right at a glance.
  • Flatten's include_arrays setting must be consistent too. If you flattened with arrays included and unflatten with auto-detect on, the round trip is clean. Mixed settings and your structure won't reassemble.

Inputs that matter

  • flat_json - the flat object with dotted keys.
  • separator - must match the flatten side.
  • auto_detect_arrays - on by default; off only when integer segments are legitimately dict keys.

Output: nested_json.

Install

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. No extra dependencies.

Troubleshooting

  • "The round trip doesn't match what I started with." Separator mismatch is the #1 cause. a.b flattened with . must be unflattened with .; the moment either side changes, keys collide or come back flat.
  • "My arrays came back as weird dicts." That's auto_detect_arrays being off, or the flattened keys not being plain integer indices. Mixed items.0 and items.foo in the same key is ambiguous - arrays need consecutive integer segments to be reliable.
  • Duplicate-ish keys. Two flat keys that collapse to the same path (a.b and a.b from different sources) - last one wins, quietly. Deduplicate before unflattening if you care.
  • Sparse arrays. items.0 and items.5 rebuild as a list with gaps or padding behavior depending on implementation. Keep indices dense unless you don't care about the holes.

The mental model: Flatten turns structure into a sortable, editable, LLM-friendly list. Unflatten turns it back into structure. Use them as a matched pair and you get the best of both - human-readable editing of deeply nested config without ever hand-editing a brace.

CategoryYogurtNodes/Logic

Inputs (3)

NameTypeDefaultDescription
flat_json*Flattened JSON object
separatoroptSTRING.Separator used in flattened keys
auto_detect_arraysoptBOOLEANtrueAutomatically detect and create arrays

Outputs (1)

NameTypeDescription
nested_json*