ComfyUI Node

JSON Parse

Turn a JSON blob into something ComfyUI can actually work with

By turnbros·Created 11 months ago·Updated 10 months ago· 0
JSON Parse
    • py_dict
    json_text{ "key": "value" }
    json_input

    JSON Parse is the front door to everything JSON-related in the ComfyBros pack. You feed it a JSON string and it hands you back a PYDICT - ComfyUI's fancy name for "a Python dictionary object." That single conversion unlocks the whole second act: once you have a PYDICT, you can pull values out of it with Dict Get, pass it around your graph, and stop fighting to keep JSON alive as plain text.

    Where does this matter? The moment your workflow touches any API response. ComfyUI nodes that talk to remote services love to return JSON as a string - metadata blobs, API payloads, image info - and strings are useless for drilling into. This node is the adapter that turns that text into structured data you can actually traverse. It also slots into the "API-first" style workflows this pack leans into: generate, parse the response, extract the field you care about.

    Inputs

    json_text is required and multiline, with a sample object as the default so you can see the shape before you replace it. The optional json_input is a wired input: connect another node's STRING output here and it takes priority over whatever's typed in json_text. That's the pattern you'll actually use in a live graph - the JSON comes from somewhere else, and this node just parses.

    How it works

    The parser is plain json.loads with two guardrails worth knowing. First, if the text isn't valid JSON, you get a ValueError with the line and column of the problem - which is dramatically more useful than ComfyUI's usual wall of traceback. Second, the root of the document has to be an object (a {}), not an array. Parse a bare [1,2,3] and it refuses, because ComfyUI's PYDICT type can only represent a dict. If you need to parse an array, wrap it: {"items": [1,2,3]}.

    Output

    One output: py_dict, a PYDICT. Wire it into Dict Get - that's the intended pairing. Dict Get can then resolve keys from it (including dotted paths like data.width) and hand you back typed values. The two nodes are halves of one flow, and JsonParse is the half you'll forget to reach for because "just paste the JSON" feels faster. It isn't, once the response is a hundred lines deep.

    Installing it

    ComfyBros installs like any custom node pack. ComfyUI Manager - search "ComfyBros" and install, restart - or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/turnbros/ComfyBros
    

    Then restart ComfyUI. The README mentions a requirements.txt that doesn't exist in the repo; the real deps are in pyproject.toml (pillow, numpy, requests) and Manager pulls those in. The node lives under ComfyBros/JSON.

    Gotchas

    The most common failure is feeding it a JSON string that has trailing commas, single quotes, or comments - that's invalid JSON to json.loads, full stop. Paste it into a validator if you're unsure. And remember the object-root rule: {"a": 1} parses, [{"a": 1}] doesn't. Neither is a bug in the node; they're both constraints of what it's allowed to return.

    CategoryComfyBros/JSON

    Inputs (2)

    NameTypeDefaultDescription
    json_textSTRING{ "key": "value" }
    json_inputoptSTRING

    Outputs (1)

    NameTypeDescription
    py_dictPYDICT