Nodes/TTools for ComfyUI/TTools Extract JSON
ComfyUI Node

TTools Extract JSON

Don't hand-build prompt lists — let TTools Extract JSON do it

By toxicwind·Created 2 years ago·Updated 2 years ago· 1
TTools Extract JSON
    • STRING
    input_string
    seed0
    max_length10
    min_part_length10
    max_part_length10
    remove_stop_words

    If your workflow ends with an LLM handing you a wall of JSON, this is the node that turns it into a prompt you can actually feed CLIP. TTools Extract JSON scans a string for every {...} object, pulls out all the values, and returns a randomized subset as one comma-separated string. Feed it a JSON blob full of phrases, and it hands you a fresh random prompt without you copy-pasting a single word.

    It's one of two nodes in toxicwind/ComfyUI-TTools, a pack whose own README describes it as "simple nodes for my various use cases." That's the honest framing. It's a small personal repo from July 2024 with no community footprint to speak of - zero search impressions on both nodes, and the author's handle doesn't show up anywhere in the r/comfyui or r/StableDiffusion corpora. Don't come here expecting support or regular updates. Do come here if you're doing LLM-driven prompt generation and want cheap, reproducible randomization.

    Why you'd reach for it. LLMs have become a normal part of ComfyUI graphs - people use API-caller nodes to have a model write captions, expand prompts, or generate batches of visual descriptions. (There's even a leftover words_to_replace.txt in the repo suggesting that's exactly what the author was doing.) The problem is that raw model output is usually one big string, and one caption means one image. This node is the bridge: it treats each value in the JSON as a candidate prompt fragment and returns a random selection each run. That's instant prompt variation for XY plots, batch queues, or just exploring a concept without typing.

    How it works. The mechanism is simple and a bit scrappy. It lowercases your whole input, regex-finds every {...} block, and json.loads each one (invalid blocks are skipped with a console message). Every value in those objects - lists get flattened too - becomes a candidate. Candidates get deduped, sorted by length, and run through punctuation-to-word replacements: / and + become "and", $ becomes "currency value of", newlines become commas. Then the list is split into short and long halves, roughly 80% of your max_length comes from the short pile and the rest from the long, and random.seed(seed) makes the whole thing reproducible.

    The inputs that actually matter. Six fields, but three of them are the whole game:

    • input_string - the text containing your JSON. Paste it, or wire an LLM output into it.
    • seed - bump it for a different random selection; keep it fixed and the node is deterministic.
    • max_length - how many fragments to return (default 10).

    The two that will bite you: min_part_length and max_part_length both default to 10, and the node only keeps values whose length falls inside that range. Set them to something like 10 and 100, or you'll filter out almost everything and wonder why your prompt came back empty. remove_stop_words uses the bundled spaCy model to strip filler words - leave it off unless your fragments come out full of "a", "the", and "of".

    The output. One STRING. Wire it straight into the positive prompt of a CLIP Text Encode node. Two honest warnings: everything is lowercased, so if your model responds to capitalization you'll lose it, and the slash-and-plug replacement means cat/dog becomes cat and dog.

    Installing it. ComfyUI Manager works if you search "TTools". Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/toxicwind/ComfyUI-TTools
    

    Now the part that will waste your afternoon: the pack's requirements.txt is broken. It lists stdlib modules (re, random, itertools, logging, json) and a package that doesn't exist on PyPI (spacy-lang-en), so pip install -r requirements.txt fails. The real dependencies are spacy, emoji, and the en_core_web_sm model:

    pip install spacy emoji
    python -m spacy download en_core_web_sm
    

    That model matters more than you'd think - the pack loads it at import time, and if it's missing, ComfyUI fails to load the whole pack and throws on startup. The __init__.py even prints the entire stop-word list to your console every launch. (There's a remove_emoji helper that nothing calls - the code is personal, not polished.) A couple more wrinkles worth knowing: the README says "cd TTools" after cloning, but the folder is actually ComfyUI-TTools, and the README claims MIT while the LICENSE file is AGPL-3.0. None of that stops the node from working. All of it is good to know before you install.

    Categoryutils

    Inputs (6)

    NameTypeDefaultDescription
    input_stringSTRING
    seedINT00–18446744073709550000
    max_lengthINT100–999999999
    min_part_lengthINT100–999999999
    max_part_lengthINT100–999999999
    remove_stop_wordsBOOLEAN

    Outputs (1)

    NameTypeDescription
    STRINGSTRING