JSON Minify and Repair
Cleaning up LLM JSON output so ComfyUI stops choking on it
- json_text
The worst part of putting an LLM in a ComfyUI workflow isn't the model - it's the JSON. Language models love to hand you valid-looking JSON with a trailing comma, a stray comment, a missing comma between fields, or three layers of pretty-printing. Downstream nodes that json.loads() it just die. UC_JSONMinifyRepair is the bridge: it takes whatever garbage text came out of a text-generation node, tries to repair the common breakages, and returns compact single-line JSON.
You'll reach for it any time a UC_TextGenerate (also in this pack) or any other LLM output needs to become structured data - feeding a UC_GetJsonValue to pull fields out, driving a workflow parameter object, or handing structured config to a scheduler. It's the kind of plumbing node that feels pointless until the day it saves you an hour of staring at a parser error.
How it works
The implementation is honest about being a repair shop, not a parser. In order, it:
- Tries
json.loads()first. Valid JSON, even pretty-printed, comes back out minified withseparators=(',', ':')- no reconstruction needed. - Strips
//line comments and/* ... */block comments (careful about the//inside URLs by requiring it not directly follow a colon). - Re-scans the text fixing the classic LLM sins - missing commas between values, and generally rebuilding the structure until it parses.
The minification is real: no whitespace beyond what's required. The output is a single json_text STRING you can drop straight into anything that parses JSON. Empty input yields "{}", so it fails soft rather than erroring.
Inputs are the whole story: one text field (multiline, paste or wire anything). Output: json_text.
Where it earns its keep
Pair it with this pack's UC_GetJsonValue, which selects a value from a top-level JSON object without mangling its type. LLM → JSONMinifyRepair → GetJsonValue is the classic chain for pulling "width", "steps", or a style tag out of a model's natural-language plan and turning it into actual workflow parameters. If you've ever watched a text-gen node produce output that looked perfect and then crashed the next node, you already know the problem this solves.
Install
Part of silveroxides/ComfyUI-UtilsCollection - one clone gets you this plus ~150 other utility, conditioning, and loader nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart, or use ComfyUI Manager and search "ComfyUI-UtilsCollection". Only deps are opencv-python and typing-extensions.
The honest limits
Don't ask it to fix deeply malformed JSON - it handles comments, missing commas, and stray whitespace, the things models actually do. If your LLM wrapped the JSON in markdown code fences or narrative prose, strip that upstream first; this node isn't a full extract the JSON from this essay tool. And because it minifies, don't use it when you actually want human-readable output - that's what the raw string was for. For its lane - LLM JSON → clean JSON - it's quietly one of the most-used nodes in the pack, and rightly so.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json_text | STRING | — |