Nodes/Lite Text to File Tools/Save Text Into JSON
ComfyUI Node

Save Text Into JSON

File anything under a key, and actually find it later

By JasonHoku·Created 7 months ago·Updated 6 months ago· 2
Save Text Into JSON
    • status
    text_input
    keydata
    file_prefixtext/data.json

    This is the node the pack's README leads with, and for good reason: it's the one with an actual workflow-shaped idea behind it. Save Text Into JSON stores any string under a key of your choosing inside a JSON object on disk. Run it once per batch item with the filename as the key and you've built a lookup table of "which image was captioned with what" that you can query forever after.

    It's from JasonHoku's Lite Text to File Tools pack - the author of the popular Ultimate Auto Sampler Config Grid Testing Suite, and this node is exactly the plumbing that kind of workflow needs. The README's example is a batch of LLM/VL outputs saved with the filename or path as the key: key: "path/or/filename", value: "a beautiful sunset". That's the use case, and it's a genuinely useful one - local text storage with zero infrastructure, no database, no API.

    How it works

    Three inputs: text_input, key, and file_prefix.

    • text_input is flagged forceInput, which is ComfyUI's way of saying "this one really wants to be wired from another node." Feed it the caption, the prompt, the result string - whatever you're collecting.
    • key is the dictionary key you're saving under. The README's convention is to use a filename or path so each item is addressable.
    • file_prefix is the JSON file path relative to ComfyUI/output/ (default text/data.json).

    On each run it loads the existing JSON object (starting fresh if the file is missing or corrupt), sets data[key] = text_value, and writes it back with 2-space indentation and UTF-8 encoding. The node sanitizes its inputs defensively - if you feed it a list or dict where it expects a string, it JSON-serializes the value instead of choking. The status output confirms the write and shows total key count: ✓ Saved key 'foo' to ... (total keys: 12).

    Important behavior: this is an upsert, not an insert. Run the same key twice and the second value wins, overwriting the first. If that's not what you want, make your keys unique per run (filenames with timestamps, seeds, whatever).

    Pair it with the read side

    The whole point is round-tripping. The pack's Load Text From JSON From Key takes the same key and file_prefix and hands the value back as a string - the README even shows the pair back to back. Wire them together and you've got a persistent key-value store living in ComfyUI/output/, which is frankly more than enough for workflow state.

    Installing it

    As with every node in the pack:

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

    Or ComfyUI Manager → search "Lite Text to File Tools". Standard library only - no pip deps, no models, nothing that can break your environment.

    Gotchas

    • Keys are strings, always. The node coerces whatever you pass - including lists - into a string key. A list key becomes something like ['a', 'b']. It won't crash, but you probably don't want that.
    • Missing file reads as an empty object, so a typo in file_prefix doesn't error - it just starts a brand-new file somewhere you weren't looking.
    • Errors come back as status strings. The node even prints a traceback to the ComfyUI console, which is genuinely useful for debugging, but the workflow itself won't stop.
    Categorylite-text-to-file

    Inputs (3)

    NameTypeDefaultDescription
    text_inputSTRING
    keySTRINGdata
    file_prefixSTRINGtext/data.json

    Outputs (1)

    NameTypeDescription
    statusSTRING