ComfyUI Node

JSON Object Iterator

Step through a JSON object's key/value pairs one run at a time

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

    This is the sibling to JSONArrayIteratorNode, built for the other common JSON shape: not a list, but a dictionary. If you've got a JSON object mapping names to values - a set of named presets, a lookup table of style-to-prompt, anything keyed rather than just listed - and you want to work through it one entry at a time across queued runs, this is the node for it.

    How it works

    Same walking mechanism as its array sibling: you give it json_input (a JSON object this time, not an array) and an index, and mode decides how that index behaves between runs. fixed pins it to whatever you set manually - good for testing one specific entry. incr and decr step the position forward or backward each time you queue, so you can set it once and run the same prompt N times to work through every key in the object, the same way you'd walk an array but by position within the object's keys rather than a list index.

    The inputs and outputs that matter

    • json_input - multiline string, a JSON object ({...}), not an array.
    • index - INT, default 0, minimum 0. Position within the object's keys.
    • mode - enum, fixed / incr / decr. This is the one you'll actually change; leave it on fixed while you're testing a single entry, switch to incr once you're ready to batch through the whole object.
    • key (output) - the key at the current position, as a STRING. Useful on its own - e.g., as a filename or a label - or as an input to JSONKeyCheckerNode if you want to gate something on it further downstream.
    • value (output) - the value at that key, as a STRING.
    • current_index / total_items (outputs) - where you are and how many entries the object has total, so you can stop or branch once you've covered everything.

    How to install it

    Same as the rest of the pack: check ComfyUI Manager for "Simple JSON Parser" or "Json Node" first, and if it's not listed, go manual:

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

    Restart. No requirements.txt, no model downloads - the entire pack is stdlib Python JSON handling, so there's nothing heavy to worry about here.

    Common issues & troubleshooting

    Fed it an array instead of an object. This node expects {...}, not [...] - if your data is actually a list, use JSONArrayIteratorNode instead. Mixing the two up will hit the "type mismatch" ValueError the README's error-handling section documents for the whole pack.

    Key order isn't what you expected. JSON objects don't have a guaranteed canonical order the way an array has index order, though in practice Python's dict (and this pack, being built on it) preserves insertion order from how the JSON was written. If you need a specific, predictable iteration order, control it by how you author the source JSON rather than assuming the node will sort or reorder it for you - it won't; there's no sort_keys-style option on this node (that's on JSONStringifierNode, a different node entirely, for output formatting).

    Stuck on fixed and it looks broken. The most common "this doesn't work" report for iterator-style nodes in general is just leaving mode on its default. fixed is the safe default for testing a single key; you have to deliberately switch to incr or decr to get the stepping behavior.

    Index runs past the number of keys. Same story as the array iterator - out-of-bounds raises rather than wrapping back to zero or stopping cleanly. Check total_items before you queue a batch count you haven't verified against the object's actual size.

    If you're choosing between this and the array iterator and you're not sure which shape your JSON is in, that's exactly what JSONParserNode with an empty path, or a quick look at the raw string, will tell you before you wire either one in.

    Categoryutils

    Inputs (3)

    NameTypeDefaultDescription
    json_inputSTRING
    indexINT0
    modeCOMBOfixed3 options: fixed, incr, decr

    Outputs (4)

    NameTypeDescription
    keySTRING
    valueSTRING
    current_indexINT
    total_itemsINT