Nodes/Lite Text to File Tools/Load Text From JSON From Key
ComfyUI Node

Load Text From JSON From Key

Pull one value out of your JSON store, with a safe fallback

By JasonHoku·Created 7 months ago·Updated 6 months ago· 2
Load Text From JSON From Key
    • text_value
    keydata
    file_prefixtext/data.json
    default_value

    Save Text Into JSON builds a key-value store on disk. This is the node that reads it back - one key at a time, with a fallback value for when the key isn't there yet. It's the lookup half of the pack's most useful pair, and the answer to "I saved all those captions by filename, now how do I get one back into my workflow?"

    It's from JasonHoku's Lite Text to File Tools pack, and it's deliberately narrow: give it a key and a file_prefix, get the matching string back. No globbing, no key lists, no iteration - just a precise read. If that sounds boring, good. That's the design.

    How it works

    The required inputs are key (which dictionary key to read, default "data") and file_prefix (the JSON file, relative to ComfyUI/output/, default text/data.json). Then there's one optional input worth knowing about:

    • default_value - what to return when the file is missing or the key isn't in it. Leave it empty and you get an error string instead; set it and the workflow keeps flowing with something sane.

    Under the hood it loads the JSON file, checks it's actually a key-value object, and returns data[key] as a string. If the stored value isn't already a string - say someone saved a nested dict - it gets JSON-serialized on the way out, so you never receive a non-string from this node. Values, keys, and file prefixes are all defensively coerced to strings, mirroring the sanitizing its write-side sibling does.

    The single output is text_value, a plain STRING, ready to feed a prompt encoder, an LLM, a Show Text node - wherever.

    The fallback is the feature

    Here's the scenario where default_value earns its keep: a workflow that reads a settings file on every run, where the setting only exists after the first run writes it. Without a fallback, the first execution hands you Error: Key 'x' not found in JSON file and that string flows into your prompt. With default_value set to something harmless, run one works fine and later runs pick up the real value once it's been saved.

    Pair it with its sibling

    The intended partner is Save Text Into JSON - same key, same file_prefix, write side and read side. The README demonstrates them back to back: save a caption under path/or/filename, load it back with the same key, get a beautiful sunset. That round-trip is the whole point of this corner of the pack.

    Installing it

    Same as the rest of the pack:

    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 dependencies, no models.

    Gotchas

    • A non-object JSON file returns an error string, not a crash. Feed it an array and you'll get Error: JSON file is not a key-value object as the output.
    • Missing key + empty default_value = error string. If you're not seeing the error in the UI, check where that output is going - it'll be hiding in a prompt or a text field somewhere downstream.
    • Keys are case-sensitive and exact. "MyKey" and "mykey" are different entries.
    Categorylite-text-to-file

    Inputs (3)

    NameTypeDefaultDescription
    keySTRINGdata
    file_prefixSTRINGtext/data.json
    default_valueoptSTRING

    Outputs (1)

    NameTypeDescription
    text_valueSTRING