ComfyUI Node

JSON Array Iterator

Walk through a JSON array one item per queued run

By Q-Bug4·Created 2 years ago·Updated about a year ago· 11
JSON Array Iterator
    • item
    • current_index
    • total_items
    json_input
    index0
    modefixed

    ComfyUI's graph is a DAG - there's no native "for each item, do this" loop. If you've got a JSON array of prompts, filenames, or seeds and you want to process them one at a time across multiple queued runs, you need something that hands you the next item each time and knows where it left off. That's what JSON Array Iterator is for. It's part of Q-Bug4's small JSON-utilities pack, and it's the node in that pack most people will actually reach for repeatedly, because "drive a batch off a list I control" is a genuinely common need that core ComfyUI just doesn't cover.

    How it works

    Give it a JSON array as a string and an index, and it hands back the item sitting at that position, plus how many items are in the array total. The interesting part is mode: fixed always returns whatever's at the literal index you set - good for testing a specific item without disturbing anything else. incr and decr step the position up or down between runs, which is what lets you queue the same prompt N times and walk through the whole array without touching a widget in between - the same idea as ComfyUI's built-in "increment after generate" behavior on primitive inputs, just applied to a JSON array position instead of a seed.

    The inputs and outputs that matter

    • json_input - multiline string, your JSON array.
    • index - INT, default 0, minimum 0. Where you start.
    • mode - enum, fixed / incr / decr. This is the knob that actually matters: pick incr if you're batch-processing forward through the list.
    • item (output) - the array element at the current position, as a STRING. This is what you wire into whatever's consuming it - a prompt input, a filename, another JSON node for further extraction if the item is itself an object.
    • current_index / total_items (outputs) - bookkeeping. Wire total_items somewhere visible if you want to know when you've reached the end of the list without counting manually.

    How to install it

    Search ComfyUI Manager for "Simple JSON Parser" or "Json Node" first - if it's not listed for you, install manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Q-Bug4/Comfyui-Simple-Json-Node
    

    Restart. No dependencies beyond Python's standard library, no models to fetch - this whole pack is string and dict manipulation, so it's a light install either way.

    Common issues & troubleshooting

    It's not actually iterating - same item every queue. Check mode is set to incr (or decr), not fixed. fixed is the default and it's easy to leave it there while testing, then wonder why your batch keeps outputting item 0 ten times in a row.

    json_input needs to be an array, not an object. If you hand this node a JSON object ({...}) instead of an array ([...]), you'll hit the same "invalid JSON string / type mismatch" ValueError the README documents for the whole pack. If your data is keyed rather than a plain list, use JSONObjectIteratorNode instead - same pack, same iteration modes, but it walks key/value pairs.

    Array index out of bounds once you hit the end. The README is explicit that out-of-range indices raise a ValueError rather than wrapping or stopping quietly. If you're queuing a fixed batch count, check it against total_items first so you don't queue past the end of the array and kill the run partway through.

    Getting a raw item, not a parsed one. The item output is always a STRING - if each array element is itself a JSON object (like the README's own users example, an array of {"name": ..., "age": ...} objects), you'll want to feed item straight into JSONParserNode or JSONKeyCheckerNode to pull specific fields out of it, rather than trying to use the raw string directly.

    The pattern that makes this genuinely useful: keep a JSON array of everything you want to generate - prompts, reference filenames, whatever - as one file or one text block, point this node at it with mode=incr, and queue the prompt N times. No wildcard files, no separate batch script, just a JSON array you can version and read at a glance.

    Categoryutils

    Inputs (3)

    NameTypeDefaultDescription
    json_inputSTRING
    indexINT0
    modeCOMBOfixed3 options: fixed, incr, decr

    Outputs (3)

    NameTypeDescription
    itemSTRING
    current_indexINT
    total_itemsINT