Nodes/ComfyUI-ADIC/字符串转JSON数组
ComfyUI Node

字符串转JSON数组

Paste text, get a JSON array string back

By jinchanz·Created about a year ago·Updated a day ago· 5
字符串转JSON数组
    • json_array
    text
    separatornewline
    remove_emptytrue
    trim_whitespacetrue

    The pack's API nodes are picky: they want JSON arrays as strings, and you have plain text. StringToJsonArray is the two-second bridge between those. You paste a list, pick a separator, and out comes a proper JSON array - the exact shape every other node in ComfyUI-ADIC wants when it says "JSON string." It's a utility, unapologetically, and it's the sort of thing you grab once and never think about again.

    The mechanism is a single split() and a json.dumps(). Your text gets split on the chosen separator - newline (default), comma, semicolon, pipe, or tab. Then two quality-of-life toggles run: trim_whitespace (default on) strips each item, and remove_empty (default on) drops blank lines so a trailing newline doesn't inject an empty string into your array. What comes out of the single json_array output is an indented JSON array string. Empty input returns [] rather than erroring.

    The inputs

    • text - required, multiline. Your list.
    • separator - how items are delimited. Newline for anything pasted from a list; comma/semicolon/pipe/tab when the data already arrives in a flattened string.
    • remove_empty - default true. Keep on unless empty items carry meaning for you.
    • trim_whitespace - default true. Keep on unless leading/trailing spaces are intentional.

    One output: json_array (STRING).

    Where it slots in

    This is the "get the data into the shape the pack expects" glue. Typical chain: paste a few URLs or IDs → StringToJsonArray → feed the result into ImageTranslateAPI's params field (through PythonCodeExecutor or a params builder), or into LoadImagesFromUrls, which auto-detects JSON arrays in its URL input. It also composes with PythonCodeExecutor if you need the same job with more transformation on top - that node's default template literally demonstrates this exact conversion.

    The honest take

    For this one narrow job, it's fine - but if you only need newline→JSON and want zero extra pack surface, PythonCodeExecutor's built-in example does the same thing, and plenty of "string to list" utilities exist in bigger packs like rgthree or KJNodes. Where this node earns its keep is convenience: no code box, just paste and go, with the toggles right there in the widget. Nothing to debug, nothing to tune, nothing to break.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/jinchanz/ComfyUI-ADIC
    

    Restart ComfyUI, or install "ComfyUI-ADIC" via ComfyUI Manager. Stdlib only - json, no pip extras, no model downloads. The README doesn't cover it (it's Chinese and translate-node-focused); behavior is exactly what the field names promise.

    CategoryMalette

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    separatoroptCOMBOnewline5 options: newline, comma, semicolon, pipe, tab
    remove_emptyoptBOOLEANtrue
    trim_whitespaceoptBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    json_arraySTRING