Nodes/comfyui_bmad_nodes/Input/String to Int Array
ComfyUI Node Runs on cloud

Input/String to Int Array

Turn '1,2,3' into an INT_ARRAY — and survive API JSON while you're at it

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
Input/String to Int Array
    • INT_ARRAY
    inStr

    Somewhere in your workflow there's a value that is secretly a list - a set of step indexes, a row of coordinates, a batch of seeds - and it keeps arriving as a comma-separated string because that's what text boxes and API bodies do. Input/String to Int Array is the node that parses it: "1,2,3" in, an INT_ARRAY out.

    It's part of the same Bmad/api/parseInput family as String to Integer and String to Float, and it was written with the pack's API story in mind. The clever bit is that the input is polymorphic. In the UI it's a plain string field (inStr), so you can type 4,8,16,32 and test it visually. But if you're driving ComfyUI from a script and your JSON payload already sends a real JSON array of integers, the node accepts that too - no string parsing needed, it just passes the list through. Same node, both worlds.

    The parse rule when it does get a string: split on commas, cast each piece with int(). "1, 2, 3" works fine (Python's int() ignores surrounding whitespace). The output, INT_ARRAY, is the pack's list type for integers - wire it into the pack's list utilities (FromListGetInts, ToIntList, etc.) to fan the values back out to individual sockets, or into any node that accepts a list of ints.

    Install

    Part of bmad4ever/comfyui_bmad_nodes:

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

    Restart, or let ComfyUI Manager handle it (search comfyui_bmad_nodes). The pack's requirements.txt pulls opencv-python~=4.8.1.78, scikit-image, gray2color, and simpleeval - none of which this tiny parser touches, but Manager installs them anyway. No model downloads.

    Gotchas

    The failure modes are all string-formatting ones. An empty string raises ValueError because int("") is meaningless - if the field can be blank, guard it upstream. A trailing comma ("1,2,3,") produces an empty piece and the same crash. And the whitespace tolerance only extends to surrounding spaces, not internal ones ("1, 2" is fine, "1,,2" is not). If your script sends a proper JSON array, you're safe regardless - that's the path the node was really built for.

    CategoryBmad/api/parseInput

    Inputs (1)

    NameTypeDefaultDescription
    inStrSTRING

    Outputs (1)

    NameTypeDescription
    INT_ARRAYINT_ARRAY