Nodes/comfyui_LLM_party/JSON Repair🐶
ComfyUI Node

JSON Repair🐶

Fix the almost-valid JSON your LLM keeps producing

By heshengtao·Created 2 years ago·Updated 6 days ago· 2,321
JSON Repair🐶
    • json_output
    input
    is_enabletrue

    Ask an LLM for JSON and you'll get JSON - most of the time. The rest of the time you'll get JSON with a trailing comma, or single quotes instead of double, or a stray sentence of explanation wrapped around it, or a code fence it wasn't asked for. None of that is valid JSON by strict parsing rules, even though it's obviously supposed to be JSON and a human could fix it in five seconds. JSON Repair is that five-second fix, automated, so a downstream node expecting strict JSON doesn't choke on output that's 95% correct.

    What it does

    Two required fields: input - the string coming from wherever your workflow produces almost-JSON, typically an LLM node prompted to return structured data - and is_enable, this pack's standard toggle. One output: json_output, the cleaned-up, hopefully now-valid JSON string.

    The mechanism isn't spelled out in the node's schema, but the name and the intent are clear enough: this is doing the same job as the well-known json_repair approach in the wider Python ecosystem - tolerantly parsing text that's almost JSON and coercing it into something a strict json.loads() will accept, rather than failing outright the way a standard JSON parser does on the first syntax error it hits. Common fixes in that category: closing an unterminated string or bracket, converting single quotes to double, stripping a trailing comma before a closing brace, and pulling the actual JSON object out from surrounding prose if the model wrapped it in commentary or a markdown code fence.

    Where it fits

    Anywhere in this pack's agent workflows where you're asking an LLM to return structured data instead of free text - a tool call's arguments, a scene layout for the Omost converter, any node further downstream that needs to parse the result as real JSON. Rather than tightening the prompt until the model behaves perfectly (which helps, but never gets you to 100%) or wrapping every downstream node in error handling for malformed input, you run the raw LLM output through this node first and let it absorb the small formatting inconsistencies that happen even with a well-behaved model.

    Installing it

    Ships with the full pack, no separate install:

    • ComfyUI Manager: search "comfyui_LLM_party", install, restart ComfyUI.
    • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/heshengtao/comfyui_LLM_party, then pip install -r requirements.txt inside your ComfyUI Python environment, restart.

    This is a lightweight text-processing node - nothing about it requires the pack's heavier local-model dependencies.

    Common issues

    Repair tools like this one are tolerant, not magic - there's a real difference between "malformed JSON that's clearly meant to represent one specific structure" and "text that's too broken or ambiguous to recover cleanly." If a model's output goes badly off the rails (half a JSON object followed by an unrelated sentence, say), don't assume this node will always produce something usable; check json_output rather than blindly trusting it downstream, especially early on while you're still tuning the upstream prompt.

    If you're consistently getting bad input to this node in the first place, that's worth fixing at the source rather than leaning on repair every time - a tighter system prompt (explicitly asking for JSON only, no explanation, no code fence) or using your model provider's native structured-output / JSON mode if it has one will get you cleaner input and make this node's job easier, faster, and more reliable than repairing consistently mangled output after the fact.

    Category大模型派对(llm_party)/转换器(converter)

    Inputs (2)

    NameTypeDefaultDescription
    inputSTRING
    is_enableBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    json_outputSTRING