Json Repair
Fix the almost-JSON your LLM node spat out
- json_string
- value
Anyone who's wired an LLM into a ComfyUI graph has hit this: you ask the model for JSON, and it gives you almost JSON. Trailing comma. A stray markdown fence around it. Single quotes. A missing closing brace. Then the next node chokes trying to parse it and your whole run dies. Json Repair is the little node that swallows that mess and gives you back valid JSON - and optionally reaches in and pulls out one field for you.
It sits in the GPT/LLM corner of shadowcz007's mixlab pack, which is where the pack starts acting like an agent toolkit rather than an image tool. Once you're using LLM nodes to plan prompts, route logic, or return structured data, you need a resilience layer between "what the model said" and "what your graph can use." This is that layer. It's unglamorous plumbing, and it's exactly the kind of node you don't know you need until a demo blows up on a missing quote.
How it works
It runs your input through a JSON-repair pass - the kind that tolerates the common LLM failure modes (trailing commas, unquoted keys, wrapping prose or code fences, mismatched brackets) and reconstructs well-formed JSON from it. If you also give it a key, it parses the repaired object and returns the value stored at that key, so you can go straight from "raw model output" to "the one string I actually wanted" without a separate parse node.
The inputs and outputs that matter
Inputs:
json_string(STRING) - the raw, possibly-broken text from your LLM node. Required.key(STRING, default empty) - a key to extract from the repaired object. Leave it blank if you just want the cleaned JSON back; set it to pull one field out.json_string2(STRING, optional) - a second JSON input, for when you're merging or handling two payloads.
Outputs:
json_string- the repaired, valid JSON.value- the value at thekeyyou asked for (as a string).
The usual pattern is: LLM node → Json Repair (with a key set) → the value flows on as a clean string into whatever needs it.
How to install it
Via ComfyUI Manager: search comfyui-mixlab-nodes, install, restart. Or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/shadowcz007/comfyui-mixlab-nodes.git
then pip install -r requirements.txt (or install.bat on the Windows portable build) and restart. No model download for this node - it's pure text processing.
Common issues & troubleshooting
value comes back empty. The key you asked for probably isn't in the object, or it's nested deeper than a top-level field. Preview the repaired json_string output first to see the actual structure, then point key at a real top-level key. Repair fixes syntax; it doesn't invent fields that were never there.
It couldn't repair it at all. Repair is forgiving, not magic. If the model returned something that isn't recognizably JSON - a paragraph of prose, a half-sentence, an empty string - there's nothing to reconstruct. The fix is upstream: tighten the LLM prompt so it actually returns JSON (ask for "only a JSON object, no explanation"), and this node cleans up the small stuff that slips through.
The value has quotes or escaping I didn't expect. Everything comes out as strings here, so a value that was itself a nested object or number arrives serialized. If you needed a number for a downstream numeric input, convert it after extraction rather than expecting a typed output.
Non-determinism. The repair is deterministic, but your LLM isn't - the same prompt can return differently-broken JSON each run. That's the point of having this node in the path at all: it absorbs that variance so the rest of the graph stays stable.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| json_string | STRING | — | |
| key | STRING | — | |
| json_string2opt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| json_string | STRING | — |
| value | STRING | — |