JsonFlatten (Yogurt Nodes)
Turn a nested config into flat keys — and back again
- json_data
- flattened_json
Nested JSON is great for storage and awful for working with in a graph. JsonFlatten takes a deeply-nested object and collapses it into flat, dot-separated keys - {"settings": {"model": "xl", "steps": 20}} becomes {"settings.model": "xl", "settings.steps": 20} - which is a shape you can iterate, filter, and reason about one row at a time.
It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), and it pairs with JsonUnflatten to make a round trip: flatten for processing, unflatten when you need the nested structure back. This is the classic "convert JSON to key-value rows" trick, and it's especially useful when you're handing structured data to an LLM node that wants a linear list, or building a table-like intermediate.
How it works
The node walks the object recursively. Every nested key gets joined with separator (default .), so depth becomes dots: a.b.c. Arrays get included by default (include_arrays, default on) as indexed keys - items.0, items.1 - so a list becomes a predictable sequence of flat keys rather than a lump. Turn include_arrays off and arrays get skipped entirely, which you want when array contents are irrelevant to what you're building.
Output is flattened_json: a flat dict where every value is a leaf - a string, number, or boolean. That's what makes it play well with other nodes: flat keys are trivial to filter with a regex, and flat values are trivial to sort or count.
Inputs that matter
json_data- the nested object.separator- default.. If your keys themselves contain dots (say, filenames), pick something else like>or/to avoid ambiguous output. The unflatten side must use the same separator, or the round trip breaks.include_arrays- default on. Off if you want to ignore array contents.
Output: flattened_json.
Install
Same pack-wide install - 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, look under Yogurt Nodes / Logic. No dependencies beyond the standard library.
Troubleshooting
- "My flat keys look wrong." If a nested key already contains your separator (a
.in a key name), the flatten is ambiguous. Changeseparatorto a character that can't appear in your keys. - "The round trip changed my data." Flatten → Unflatten is lossless if the separator matches and you keep
include_arraysconsistent on both sides. Mismatched settings are the #1 source of "where did my structure go." - Ordering. The flattened output follows the traversal order, which for dicts means insertion order. Don't rely on it being sorted - sort downstream if you need deterministic order.
The practical move: flatten a config, show it as text, let an LLM or a human eyeball the whole config in one flat list, then unflatten the edited version. Much easier than asking a model to edit a deeply nested blob and hoping it doesn't drop a brace.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| json_data | * | JSON object to flatten | |
| separatoropt | STRING | . | Separator for nested keys |
| include_arraysopt | BOOLEAN | true | Include array elements with index |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| flattened_json | * | — |