ComfyUI Node

JSON Parse

Split your LLM's JSON into strings without writing a line of code

By Moeblack·Created 9 months ago·Updated 7 months ago· 8
JSON Parse
    • out1
    • out2
    • out3
    • out4
    • out5
    • out6
    • out7
    • out8
    • obj
    json_text
    strip_code_fencetrue
    default
    path1
    path2
    path3
    path4
    path5
    path6
    path7
    path8

    The moment your LLM starts returning structured output, you need a way to crack the JSON open in the graph. JSON Parse is that tool: it takes a JSON string - the kind a Chat node hands back when you ask for structured output - and extracts up to eight values by dot/bracket paths, each on its own output port. No Python, no scripting node, just a path string per port.

    How it works

    You give it json_text plus up to eight path fields. Paths are the familiar dot/bracket syntax: positive, params.width, items[0].name, items[0]["name"]. It walks the parsed object and lands each value on the matching out1out8 port as a STRING (numbers and booleans get stringified, nested objects come back as JSON text). There's also a obj output that carries the whole parsed object on the pack's SIMPLECHAT_JSON type, for chaining into other SimpleChat nodes.

    Three niceties baked in:

    • Code fences auto-stripped - strip_code_fence defaults on, so a reply wrapped in ```json ... ``` still parses. LLMs love wrapping their JSON; this saves you a cleanup step.
    • A default value - the default input (default "") is what a port gets when a path isn't found. Keeps missing keys from erroring the whole graph.
    • Strict-ish parsing - it's a straightforward json.loads with fence-stripping, so well-formed output is fine and malformed output errors loudly (unlike the forgiving parsers in Prompt JSON Unpack).

    Why it beats manual copy-paste

    Because it runs live. In the flagship loop, Chat → JSON reply → this node → eight string ports wired into your sampler's prompt and parameter slots. Ask the LLM for {"positive": ..., "negative": ..., "seed": ...} and re-run with a different request to iterate without ever touching the node. It's the manual version of Prompt JSON Unpack - which is exactly the trade: this one takes any schema via paths, the other is fixed-schema but gives you typed INT/FLOAT/SAMPLER outputs. If your JSON matches the Anima prompt schema, use Prompt JSON Unpack and skip the path typing; if your schema is your own, this is the one.

    Installing it

    cd ComfyUI/custom_nodes
    git clone https://github.com/Moeblack/ComfyUI-SimpleChat
    

    Restart, or use Manager and search "ComfyUI-SimpleChat". Only dependency: aiohttp.

    Gotchas

    Eight ports is a hard ceiling - for sixteen, use the pack's JSON Parse (16) variant. Values come out as strings, so if you wire out3 (a number) into an INT input you'll need Prompt JSON Unpack-style casting or a convert node; this node won't do it. And remember it needs a string of JSON - if your upstream hands you the already-parsed SIMPLECHAT_JSON object, you want JSON -> Vars or a direct obj consumer instead.

    CategorySimpleChat/Utils

    Inputs (11)

    NameTypeDefaultDescription
    json_textSTRING
    strip_code_fenceBOOLEANtrue
    defaultSTRING
    path1STRING
    path2STRING
    path3STRING
    path4STRING
    path5STRING
    path6STRING
    path7STRING
    path8STRING

    Outputs (9)

    NameTypeDescription
    out1STRING
    out2STRING
    out3STRING
    out4STRING
    out5STRING
    out6STRING
    out7STRING
    out8STRING
    objSIMPLECHAT_JSON