Dataset → Write JSON
Records-oriented output that reads straight back in
- dataset
- file
What it is
ComfyDL is Cynthia-lxx's d2l-derived deep-learning pack for ComfyUI: dataset readers, adapters, trainers and writers all trading one universal DATASET object (features, optional labels, column names) around the graph by reference. Dataset → Write JSON is the simplest of the four writers - no optional widgets at all - and the one that exists because JSON is what everything else in the world reads.
Reach for it when the dataset's next stop is outside ComfyUI: a JavaScript front end, a webhook, a small service, an annotation round trip. Or when you want a human-readable dump of a converted file, since a JSON of records shows each row's field names in place rather than making you count commas in a header line.
How it works
One call, basically:
df.to_json(file, orient="records")
The dataset is first materialised into a DataFrame by to_dataframe() - features from the stored tensor plus the column names, and the label column named after the dataset's target (falling back to label) - then serialised as a list of row objects. So a DATASET with features x0, x1 and a target called y becomes:
[{"x0": 0.0, "x1": 1.0, "y": 0.0}, {"x0": 1.0, "x1": 3.0, "y": 0.5}]
The reason that matters is the round trip: the pack's Read JSON → Dataset is built on pd.read_json, which happily ingests exactly this shape. The two nodes are designed as a pair, which makes them a clean way to stash a dataset and pick it up later with column names and the label intact.
Inputs and outputs
Required: dataset (a forced input socket - it must be wired) and file (STRING, default dataset_out.json). There is no optional input: no pretty-printing toggle, no orient selector, no index option.
Output: file, a STRING for chaining into another node's path field.
Install
Manager → search ComfyDL, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt
Restart. The pack's own requirements are only matplotlib, IPython and matplotlib-inline; pandas is unlisted but required by every reader and writer here, so pip install pandas if it isn't already in your venv. If nodes are absent from the menu rather than erroring, check the console for [ComfyDL] Warning: Failed to load <module> - this pack swallows per-module import failures.
Where people get burned
It's one long line. to_json writes compact JSON, not pretty-printed, so a 50,000-row dataset is a single enormous line of text. Fine for machines, miserable for humans, and some editors will choke on opening it. If you want something readable, take the CSV writer instead - or lean on the fact that you can route the path onward and format it elsewhere.
No name for the label means a column called label. A DATASET assembled via Tensors → Dataset has no target name, so the JSON key is literally label. The data's all there; the header just won't match your source file.
Column names are whatever the reader found - including the Unnamed: 0 that a spreadsheet's index column can produce. JSON makes those names very visible, which is either a feature or an annoyance.
Paths. Relative filenames resolve against ComfyUI's process working directory, and the file is overwritten silently each run. Absolute paths, and don't reuse a filename you care about.
No streaming. The DataFrame and the serialised string both exist in memory at once, so very large datasets are better served by the DB writer, which chunks. And like every writer here, it writes NaN values through untouched - a NaN source stays a NaN destination.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dataset | DATASET | — | |
| file | STRING | dataset_out.json | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| file | STRING | — |