📜 文本数组格式化器
Turn a JSON string array into a real LIST_STR — with a caveat
- 长度
- 字符串数组
LLMs are great at spitting out JSON arrays of text - captions, tag lists, candidate prompts, shot descriptions - and terrible at handing them to ComfyUI in a usable form, because what comes back is just a string. This node, "📜 文本数组格式化器", parses a JSON-format string array and outputs a real LIST_STR plus its length, so the text can flow into nodes that consume actual lists. It's the cleanup step between "LLM said something" and "workflow can iterate over it."
How it works
Feed it a string that looks like ["text one", "text two", "text three"] and it runs json.loads, verifies you actually gave it an array, coerces every element to a string (in case the LLM slipped in a number or boolean), and returns the parsed list alongside its length. Malformed input doesn't crash - you get a zero-length list and a Chinese log line ("解析失败", parse failed) in the console. Since it's an output node with IS_CHANGED hashing its input, it re-runs only when the input string actually changes, which matters when the string comes from an LLM call you don't want re-triggering.
Inputs and outputs
input_str(STRING, multiline) - the JSON array text.show_index(BOOLEAN),max_length(INT),delimiter(STRING) - and here's the honest caveat: these exist on the node but the current code largely ignores them. The docstring describes a fancier formatter (index prefixes, truncation, delimiter escaping), butformat_arrayas shipped just validates and returns the raw list plus its length. Don't set expectations that elements come out reformatted - they don't. Maybe a future update finishes the job.- Outputs:
长度("length", INT) and字符串数组("string array", LIST_STR).
Wiring it up
The LIST_STR output is the thing the rest of the pack's text nodes want: feed it straight into StringArrayIndexer to pull individual elements, or into any list-consuming node in the wider ecosystem. The 长度 output is handy for sanity checks and loop bounds - an LLM returning a variable-length array becomes something you can drive logic from.
Installing it
ComfyUI Manager → search comfyUI_LLM, or:
cd ComfyUI/custom_nodes
git clone https://github.com/XieJunchen/comfyUI_LLM
# restart ComfyUI
Pure Python stdlib, no extra dependencies.
Where people get burned
- Strict JSON expected. Trailing commas, single quotes, or an LLM that wrapped the array in prose will fail the parse and silently produce an empty list. Ask your LLM for just the JSON, or clean the string first.
- Non-array JSON → empty list. A plain string or object input gets rejected, not converted.
- The formatter params are decorative today. If you came expecting index/truncation formatting, you'll be underwhelmed - this node is currently a validator + converter.
For "LLM returned an array, now make it usable," it's a small, dependable bridge. Just don't expect it to format anything.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input_str | STRING | ["示例文本1", "示例文本2"] | — |
| show_index | BOOLEAN | true | — |
| max_length | INT | 2000–65535 | — |
| delimiteropt | STRING | | | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 长度 | INT | — |
| 字符串数组 | LIST_STR | — |