Text Custom Extract
Pull one key out of messy LLM JSON without fighting the parser
- string
The moment you wire a vision model or LLM into ComfyUI, you discover that JSON parsers hate language models. The model wraps the JSON in ``` fences, uses single quotes instead of double, or emits a half-valid blob with a trailing comma. Text Custom Extract (1hew_TextCustomExtract) is built for exactly that world - it's a JSON extractor that shrugs at malformed input and pulls out the one key you asked for.
It comes from the 1hewNodes/text group of the 1hewNodes pack, and it's clearly written to live downstream of captioning and object-detection LLMs.
How it works
Three layers of forgiveness. First, it strips code fences (json ... ) and finds the outermost { or [. Then it tries strict json.loads, falls back to Python literal parsing, then to swapping single quotes for double, then to a loose hand-rolled parser that tolerates unquoted keys and other sins, and finally to a regex key-value sweep. For real, most things you paste in here parse.
Then comes the key lookup, which is the feature that gives the node its identity. The key input defaults to "zh", and it's matched fuzzily: zh will find zh, ZH, chinese, Chinese, 中文, and friends. Same for en, bbox, label, confidence, x, y, width, height. This is aimed squarely at bilingual captioning models that return {zh: "...", en: "..."} - extract the Chinese caption with key: zh and the English with key: en. If you want exact key matching and nothing else, set precision_match to enabled.
Inputs and outputs
- json_data - the messy text. Multiline.
- key - which key to pull, fuzzy-matched by default (
"zh"default). - precision_match -
disabled(default) orenabled. - label_filter - comma-separated substrings; only returns values from list items whose
labelfield contains one of them. Built for object-detection JSON. - string - the extracted value as a plain string (lists of numbers come out comma-joined).
Installing it
It's part of the 1hewNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
or via ComfyUI Manager ("1hewNodes"), then restart. Pure text parsing - no models, no downloads.
The trap to avoid
The label_filter is great and slightly surprising: it's a substring filter, so person will match "person", "people", and "person sitting". If you need exact labels, you'll be disappointed. Also note that when json_data is a list, the output joins all matching values with newlines - one line per list item. That's usually what you want from a detector (all the labels), but if you expected a single value, check whether your input was a dict (single result) or a list (multi-line). Once you know that, this is the least-frustrating text extractor in the pack.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| json_data | STRING | — | |
| key | STRING | zh | — |
| precision_match | COMBO | disabled | 2 options: disabled, enabled |
| label_filter | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |