π€ Dataset Flatten
Unwrap nested columns β turn that JSON-in-a-cell into real columns
- dataset
- dataset
A surprising number of Hub datasets store structured data as nested columns - a metadata cell holding a dict, or a cell holding a list of values. That's fine for Python, where you can reach in with row["metadata"]["author"], but it's a wall in a graph node that only sees top-level columns. π€ Dataset Flatten knocks that wall down: it expands nested dicts and lists into plain top-level columns, one per inner key.
How it works
It's datasets.Dataset.flatten as a node. One input, one output - this is the most self-contained node in the pack:
datasetin,datasetout, no widgets to set.
Flatten walks each row and promotes nested structure to the top level: a metadata column holding {"author": "x", "year": 2020} becomes two columns named like metadata.author and metadata.year. List cells expand to sequence columns (list.field) where the library can. Afterward, everything the nested data contained is a first-class column your other π€ nodes can filter on, select, sort by, or rename - which is the whole point. A nested metadata.author you can't reference becomes a column you can feed straight into a Filter.
Read this before running it
Two caveats, and they're both structural. First, loaded-only: flatten needs a fully materialized datasets.Dataset, so if your loader has streaming on you'll get the pack's standard "disable streaming" error - flatten a lazy stream would be surprising anyway, since it has to reshape every row's schema. Second, flatten is one-way in practice: promoted columns keep a dotted name, and you may end up with long column names if your nesting is deep. That's cosmetic, but it's why the rename node is a good neighbor to keep around.
It's also worth knowing that flatten is not magic for arbitrary JSON blobs - it handles the dict/list nesting datasets itself models. If a column is genuinely free-form text that happens to look like JSON, that's parsing, not flattening, and this node isn't the tool.
Installing it
Part of StableLlama/ComfyUI-huggingface_dataset. ComfyUI-Manager β search "Hugging Face dataset", or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-huggingface_dataset
pip install -r requirements.txt
Restart ComfyUI. Only runtime dependency is datasets, installed for you by Manager. If your dataset's nested columns never seem to matter, that's usually because your use case never reached into them - flatten is what makes them reachable.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| dataset | HUGGINGFACE_DATASET | Fully-loaded dataset whose nested columns to flatten (from the π€ Dataset Loader). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| dataset | HUGGINGFACE_DATASET | The dataset with nested columns expanded to top level. |