Nodes/Quality of Life Nodes for ComfyUI/JSON Array Iterator (Soze)
ComfyUI Node

JSON Array Iterator (Soze)

Walk a JSON array one item per run

By SozeInc·Created 2 years ago·Updated 5 days ago· 10
JSON Array Iterator (Soze)
    • item
    • current_index
    • total_items
    json_input
    index0

    Say you've got a JSON array of prompts, filenames, or config entries and you want ComfyUI to run once per item - a batch job, basically, but driven by data instead of by ComfyUI's built-in batch count. JSON Array Iterator is the node that makes that possible: give it the array and an index, and it hands back the single item living at that index, plus enough bookkeeping (current position, total count) to drive the loop.

    The pattern is: set ComfyUI's queue to run N times (N = your array length), and either increment index manually between runs or drive it from another counter node. Each run, this node pulls a different item and the rest of your graph processes it.

    How it works

    It parses json_input as a JSON array, indexes into it with index, and returns the element at that position as a string (so if your array holds objects rather than plain strings, you'll likely want to follow this with a JSON Path Extractor to pull specific fields back out). It also reports total_items, so you can wire that into whatever's controlling your loop count without hardcoding the array length twice.

    One thing worth flagging: the index field's tooltip in the node itself reads "The row number to read from the CSV file" - that's almost certainly boilerplate carried over from the pack's CSV Reader nodes (the README describes a matching index-driven pattern for CSV rows), not an actual CSV dependency. This node reads a JSON array, not a CSV file; ignore the tooltip's wording and trust the field name.

    The inputs and outputs that matter

    • json_input - required, multiline. Your JSON array as a string.
    • index - required, default 0, range 0 to 1,000,000. The position to read. Despite the tooltip's wording, this indexes into your JSON array, not a CSV row.
    • Output: item - the array element at index, as a string.
    • Output: current_index - echoes index back, handy for labeling outputs or feeding a filename builder without a second wire from the input widget.
    • Output: total_items - the array's length. Wire this to whatever sets your loop bound.

    How to install it

    Via ComfyUI Manager (search "Quality of Life Nodes for ComfyUI" or "Soze"), or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/SozeInc/ComfyUI_Soze.git
    pip install -r ComfyUI_Soze/requirements.txt
    

    Restart ComfyUI. No models, no GPU dependency, no API keys - this is a plain JSON utility.

    Common issues & troubleshooting

    item comes back as a whole JSON object string, not a clean value. That's expected if your array holds objects rather than scalars - this node hands you the raw element, formatting included. Chain JSON Path Extractor or JSON Formatter after it if you need a specific field out.

    index runs past the array length. Since the widget's max is 1,000,000 regardless of your actual array size, nothing stops you from setting an index beyond total_items - check total_items first (or wire this alongside JSON Get Array Count) so your loop bound matches the real array size.

    Confusing the tooltip for real behavior. As noted above, the "row number... from the CSV file" tooltip is a labeling leftover from a sibling node group in the same pack - don't go looking for CSV-specific requirements or a CSV file input that doesn't exist on this node.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    json_inputSTRING
    indexINT00–1000000The row number to read from the CSV file.

    Outputs (3)

    NameTypeDescription
    itemSTRING
    current_indexINT
    total_itemsINT