ComfyUI Node

IW JsonPickItem

Grab one item from a JSON list, on a wire you control

By iwanders·Created 2 years ago·Updated 6 months ago· 2
IW JsonPickItem
    • STRING
    pick_value0
    input

    IW JsonPickItem takes a JSON array and an integer, and returns one element of that array as a string. It's the selection node in the iwanders/ComfyUI_nodes pack - the piece that turns a pile of JSON on a wire into "the one I want right now."

    The mechanics are simple: it parses the input with json.loads, indexes it with pick_value, and returns the chosen element re-serialized as JSON. One detail makes it more useful than it looks: the index is taken modulo the list length. Pick 7 on a 3-element list wraps around to index 1, and negative picks resolve sensibly too. That means you can drive it with a counter or a seed and let it cycle forever without ever hitting an out-of-range error - which is exactly the behavior you want when you're farming variations.

    What it's actually for

    The pattern that makes this node earn its place: you keep a list of prompts, seeds, or configs as a JSON file - saved with the pack's IW SaveString in json mode, say - and you feed its contents in as the input (read a file with a text node, or wire the output of whatever produced the JSON). Then pick_value selects which entry you're running this batch. Wire pick_value to a seed or a manual int, and one node gives you "iterate through my saved configs" without any Python.

    It's also handy when another node hands you a JSON array and you need just the first result, or when you're pulling from an API-style payload and want element N. If the input is valid JSON but not a list, the behavior gets weird: an object throws an error, and a bare JSON string just indexes into the characters - you'd silently get one character instead of a meaningful item. This node wants a list, and it's not shy about assuming you gave it one.

    What you set

    • input - the JSON, multiline, paste or wire it.
    • pick_value - the index, an INT with wired input enabled by default.

    Output is a single STRING. Note that the chosen item is returned as JSON, so a string element comes back with its quotes, "hello" - if you need the bare text, run it through the pack's IW ReplaceString in json mode or just keep that in mind when wiring.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/iwanders/ComfyUI_nodes
    

    Restart ComfyUI, or search iwanders in ComfyUI Manager. No dependencies, no downloads. If you've ever wanted to loop a workflow over a saved list of prompts without rebuilding the graph, this is the missing link.

    Categoryiw

    Inputs (2)

    NameTypeDefaultDescription
    pick_valueINT0
    inputSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING