Nodes/ComfyUI-YogurtNodes/JsonParse (Yogurt Nodes)
ComfyUI Node

JsonParse (Yogurt Nodes)

Turn a JSON string into a real object the graph can use

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
JsonParse (Yogurt Nodes)
    • json_object
    json_string
    stricttrue

    ComfyUI hands you strings everywhere - API responses, saved workflow metadata, an LLM node's "structured output" that came back as text. And a string of JSON is just a string until you parse it. JsonParse is the conversion: feed it the text, get back an actual object (dicts, lists, numbers) that other JSON nodes - GetPath, Merge, Stringify - can work with.

    It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), and the usual entry point to the pack's JSON toolkit. If you're doing anything where a model or a web service hands you JSON-as-text, this is step one.

    How it works

    Straightforward: it runs Python's json.loads on the input and returns the resulting object as json_object. The interesting knob is strict (default on). Strict mode is the spec-compliant json.loads - it will reject single-quoted strings, trailing commas, and comments. Turn strict off and the node first swaps single quotes for double quotes before parsing, which rescues a lot of sloppy-but-common JSON emitted by LLMs. That's the mode to reach for when your model "forgot" to use proper double quotes.

    If the input genuinely isn't valid JSON, the node raises a clear Invalid JSON error rather than silently returning garbage - which is the right behavior, because garbage would otherwise flow through your whole graph.

    Inputs that matter

    • json_string - the text to parse. Multiline widget, so paste freely.
    • strict - on by default. Turn off only when you're dealing with single-quoted output from a model; it's a heuristic, not a license to feed it anything.

    Output: json_object.

    Install

    Pack-wide routine - ComfyUI Manager (search "YogurtNodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
    cd ComfyUI-YogurtNodes
    pip install -r requirements.txt
    

    Restart, find it under Yogurt Nodes / Logic. No dependencies beyond the standard library.

    Troubleshooting

    • "Invalid JSON" and I copied it from a model. Classic LLM output problems: single quotes, trailing commas, markdown code fences around the JSON. Turn strict off for the quote issue; strip backticks before parsing for the fence issue. If there's prose wrapped around the JSON, you need a node that extracts the JSON first - this one expects clean input.
    • "It parsed but everything is one giant string." You got a JSON string containing a JSON string - double-encoded. Run it through Parse again (or fix whatever double-encoded it upstream).
    • Leading BOM / whitespace. Rare, but some APIs prepend a byte-order mark that makes json.loads complain. If you see a cryptic error on input that looks fine, that's the suspect.
    • Type expectations. A JSON array parses to a list, an object to a dict, true/false/null to Python booleans/None. If a downstream node expects a dict and you fed it an array, that's a shape mismatch, not a parse failure.

    Rule of thumb: Parse at the boundary - right where text enters your graph - and everything downstream gets to think in objects instead of strings. Pair it with JsonValidate when you want to confirm the shape before trusting it.

    CategoryYogurtNodes/Logic

    Inputs (2)

    NameTypeDefaultDescription
    json_stringSTRINGJSON string to parse
    strictoptBOOLEANtrueUse strict JSON parsing

    Outputs (1)

    NameTypeDescription
    json_object*