Nodes/ComfyDL/Read JSON → Dataset
ComfyUI Node

Read JSON → Dataset

Flat records only, and it round-trips with the pack's JSON writer

By Cynthia-lxx·Created 3 months ago·Updated 12 days ago· 7
Read JSON → Dataset
    • dataset
    ◄filecdl_dataset.json►
    ◄target►
    ◄dtypefloat32►

    What it is

    ComfyDL is Cynthia-lxx's pack for building deep-learning workflows as ComfyUI graphs - d2l-derived textbook nodes, from-scratch trainers, no diffusion involved. Its DATASET type is a single socket carrying features, optional labels and column names, passed by reference between the data nodes.

    Read JSON → Dataset is one of seven readers that produce that type. It exists for the moment your data already lives in JSON - an API response you saved, an export from some annotation tool, a config where the numbers are in a list of objects. You don't want to open a terminal and convert it; you want a node.

    How it works

    It's pd.read_json(file) followed by the pack's standard CdlDataset.from_dataframe. Pandas infers the orientation, so the two shapes that work are:

    [{"x1": 1, "x2": 5, "y": 2.5}, {"x1": 2, "x2": 7, "y": 3.1}]
    

    a list of records (one object per row), or a dictionary of columns where each key maps to a list of values. Either becomes a DataFrame; then target names the label column, that column is popped off into a labels tensor, everything left becomes a float32/float64 feature tensor built with torch.from_numpy, and the column names travel with the dataset.

    Because it's pd.read_json with no extra arguments, it's reading tabular JSON. Anything nested - a list of dicts where one field is itself an object or an array - lands in a cell as a Python object, and the float conversion downstream has nothing to convert.

    Inputs and outputs

    Required: file (default cdl_dataset.json) and target (column name; empty = no labels). Optional: dtype (float32 or float64).

    Output: one dataset socket, ready for Dataset → Preview, the writers, the adapters, or a trainer.

    Install

    Manager → search ComfyDL, or clone it yourself:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Cynthia-lxx/ComfyDL
    pip install -r ./ComfyDL/requirements.txt
    

    Restart ComfyUI afterwards. The declared requirements are only matplotlib, IPython and matplotlib-inline - pandas, which all the readers use, isn't listed and is assumed to be in your ComfyUI environment already. And since the pack loads node modules in a try/except that only prints [ComfyDL] Warning: Failed to load <module>, a broken import can surface as "the node is missing" rather than an error dialog. Console first.

    The round trip you'll actually use

    The pack's Dataset → Write JSON writes with orient="records" - exactly the shape this node reads best. So Read CSV → Dataset → Write JSON is a legitimate conversion pipeline, and it's the reason the two defaults (dataset_out.json) are worth setting deliberately rather than leaving as-is. Remember that widget strings are just strings: to chain writer→reader, right-click the reader's file widget and convert it to an input, then wire the writer's file output into it.

    Where people get burned

    Nested values. A record like {"x": 1, "meta": {"site": "a"}} gives you a column of dicts, not rows. Flatten before it reaches the node.

    Text columns. Category names, ISO dates, string IDs - the reader keeps every non-target column and converts it to float, so anything unparseable raises a numpy conversion error. Your features must already be numbers, or numeric strings.

    Column names are matched exactly for target, including case. A near-miss gives target column not found in DataFrame.

    Relative paths resolve against ComfyUI's working directory, not the folder you're browsing in. Absolute paths save an hour of confusion.

    Objects with wildly different keys. In a list of records, missing keys become NaN. Nothing drops or fills them, so a sparse export quietly becomes a matrix full of NaNs and your loss goes NaN a few steps into training.

    No chunking. Pandas parses the whole file and the node keeps the tensors resident for the run. Large exports belong in the CSV or DB path.

    Categoryd2l/Datasets

    Inputs (3)

    NameTypeDefaultDescription
    fileSTRINGcdl_dataset.json—
    targetSTRING—
    dtypeoptCOMBOfloat322 options: float32, float64

    Outputs (1)

    NameTypeDescription
    datasetDATASET—