Nodes/comfyui_LLM_party/JSON Iterator
ComfyUI Node

JSON Iterator

Step through a JSON list one item per run

By heshengtao·Created 2 years ago·Updated 7 days ago· 2,321
JSON Iterator
    • file_content
    • is_end
    json_str{"key": "value"}
    is_enabletrue
    is_reloadfalse
    load_allfalse
    iterator_modesequential

    Agent workflows often need to process a list of things one at a time - a batch of prompts, a queue of tasks, a set of records - running the same LLM logic against each item and stepping forward on every pass through the graph. json_iterator is this pack's engine for that: give it JSON content, and it walks through it item by item across repeated runs, instead of you having to build that state-tracking yourself.

    How it works

    You hand it json_str, and on each execution it advances its internal position and hands back the current item as file_content, plus a flag telling you whether you've reached the end. Pair it with FolderCleaner for pre-loop cleanup and json_writing for logging each result, and you have the pack's standard "loop over N things, do work, record it" shape.

    The inputs and outputs that matter

    • json_str (default {"key": "value"}) - your data source. Despite the default looking like a single literal object, this is meant to hold the actual content you're iterating over - practically, that means a JSON list of items you want processed one at a time.
    • iterator_mode - sequential (in order), random (shuffled), Infinite (loops around instead of stopping at the end), or sequential_flagout (also sequential; the schema doesn't spell out exactly how its end-of-loop signaling differs from plain sequential - if your downstream logic depends on precisely when is_end fires, test both against a small list before trusting either in a long-running loop).
    • is_reload (default false) - resets the iterator's position back to the start when enabled, for restarting a loop from scratch.
    • load_all (default false) - returns everything at once instead of one item per run, when you want the full list rather than stepping through it.
    • is_enable - standard bypass toggle.

    Outputs: file_content (STRING) - the current item. is_end (BOOLEAN) - whether the iterator has reached the end of the list, the signal your loop-control logic checks to know when to stop.

    How to install it

    Via ComfyUI Manager: search comfyui_LLM_party, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/heshengtao/comfyui_LLM_party.git
    

    Then pip install -r requirements.txt from inside the pack folder using ComfyUI's own Python, and restart. No models or keys needed for this node itself.

    Common issues & troubleshooting

    The loop never stops. Check iterator_mode isn't set to Infinite when you actually wanted it to terminate - that mode wraps around on purpose rather than signaling is_end.

    Re-running the graph doesn't restart from item one. By default the iterator remembers its position across runs, which is the point for a genuine multi-run loop - but if you actually wanted a fresh start, enable is_reload rather than assuming a new queue run resets it automatically.

    You expected one item per run and got the whole list. That's load_all - leave it false for genuine one-at-a-time iteration, and only flip it on when you deliberately want everything at once.

    is_end fires at an unexpected point. This is the one place the schema leaves real ambiguity - between sequential and sequential_flagout in particular, don't assume identical end-of-loop behavior; verify against your actual list before relying on it for anything that matters.

    Category大模型派对(llm_party)/迭代器(iterator)

    Inputs (5)

    NameTypeDefaultDescription
    json_strSTRING{"key": "value"}
    is_enableBOOLEANtrue
    is_reloadBOOLEANfalse
    load_allBOOLEANfalse
    iterator_modeCOMBOsequential4 options: sequential, random, Infinite, sequential_flagout

    Outputs (2)

    NameTypeDescription
    file_contentSTRING
    is_endBOOLEAN