Nodes/Lite Text to File Tools/Append Input To JSON Array File
ComfyUI Node

Append Input To JSON Array File

Collect batch results one append at a time

By JasonHoku·Created 7 months ago·Updated 6 months ago· 2
Append Input To JSON Array File
    • status
    text_input
    file_prefixtext/lite-text.json

    If you've ever run a ComfyUI batch, waited for the whole thing, and then realized you never captured the individual results anywhere - this is the node for that. Append Input To JSON Array File grows a JSON array on disk one entry per execution. Every run adds a new item to the list, so you end up with a structured record of everything the batch produced, instead of a stack of images and a vague memory.

    It's part of JasonHoku's Lite Text to File Tools pack, and it's the natural companion to a batch that emits a different string each pass - say, an LLM captioning node labeling each image, or a filename generator. Feed it the string, it appends to the array. Nothing smarter, nothing sneakier.

    How it works

    Two inputs: text_input (the string to store) and file_prefix (the file path, relative to ComfyUI/output/). The default is text/lite-text.json, so out of the box you're writing to ComfyUI/output/text/lite-text.json.

    On each run it reads the existing file, makes sure the data is a list, appends your new string, and writes it back with nice two-space indentation and UTF-8 encoding. Three edge cases are handled for you:

    • File doesn't exist yet → starts with an empty array and appends the first item.
    • File is corrupted / not valid JSON → discards the garbage and starts fresh (your bad data is gone, but the workflow keeps running).
    • File is a JSON object instead of an array → wraps the existing object into a one-item list rather than erroring.

    The status output reports what happened, including a running count: ✓ Appended to ... (total items: 7). It's an output node, so you can hook that status into a Show Text node to watch the array grow while a long batch runs.

    What you'd use it for

    • Dataset building. Run a batch, pipe each caption or prompt into this node, and you've assembled a JSONL-ish array you can train or review later.
    • Prompt history. Log every positive prompt you generated with, then query it later with the pack's Load Text From JSON Array By Index node.
    • LLM/VL output collection. This pack's README literally calls out batching LLM vision outputs - the array is a tidy place to accumulate them run by run.

    Installing it

    It's one of nine nodes in the Lite Text to File Tools pack, so the install is shared:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/JasonHoku/comfyui-lite-text-to-file-tools
    # restart ComfyUI
    

    Or search "Lite Text to File Tools" in ComfyUI Manager. No extra Python packages, no models - just the standard library.

    Gotchas

    • Errors are returned as a status string, not raised, so a bad file_prefix won't stop the batch - you'll just get ✗ Error: ... in the status.
    • There's no cap and no dedupe. Run the same prompt ten times, you get ten identical entries. That's on you.
    • Want a fresh array for a new run? That's what the pack's Clear JSON Array File node is for - wire it first and this node starts from zero.
    Categorylite-text-to-file

    Inputs (2)

    NameTypeDefaultDescription
    text_inputSTRING
    file_prefixSTRINGtext/lite-text.json

    Outputs (1)

    NameTypeDescription
    statusSTRING