Nodes/Plush-for-ComfyUI/Extract JSON data🧸
ComfyUI Node

Extract JSON data🧸

Pull fields out of an LLM's JSON reply by key

By glibsonoran·Created 3 years ago·Updated about a year ago· 197
Extract JSON data🧸
    • string_1
    • string_2
    • string_3
    • string_4
    • string_5
    • JSON_Obj
    • help
    • Troubleshooting
    key_1
    key_2
    key_3
    key_4
    key_5
    json_string

    When you get an LLM to reply in structured JSON, you need a way to pull the pieces back out. Extract JSON data does exactly that: give it a JSON string and up to five keys, and it hands you back the value for each key as a separate string output. It turns "the model returned a blob of JSON" into "here are five clean strings I can wire wherever I want."

    This is the companion to forcing JSON output. On its own it's just a parser, but paired with a model that returns structured data it's what makes an LLM behave like a reliable component instead of a chatterbox.

    How it works

    You feed the json_string input (usually piped from Advanced Prompt Enhancer, after you've told the model to reply in JSON) and type the keys you want into key_1 through key_5. The node parses the JSON, looks up each key, and outputs the matching value on string_1 through string_5. It also gives you the whole parsed object on a JSON_Obj output for anything that wants the full structure.

    The typical setup: use the Add Parameters node to set response_format to JSON (or pick the "OpenAI JSON Format" option there), which forces the model to return valid JSON, then run its output through this node to break it into fields. The pack ships an example workflow showing this combo.

    The inputs and outputs

    • json_string (optional, multiline): the JSON to parse.
    • key_1 ... key_5: the keys to look up. Leave any blank to skip. These match the top-level field names in your JSON.

    Outputs: string_1 ... string_5 (the value for each key), JSON_Obj (the full parsed dictionary), plus help and Troubleshooting. Wire each string to wherever that field needs to go, a prompt, a filename, a switch.

    Why you'd bother

    Structured output is how you get an LLM to make decisions inside a workflow. Ask it to return {"style": "...", "subject": "...", "mood": "..."} and suddenly you can route each piece independently instead of parsing free text with string hacks. This node is the "instead of string hacks" part. It's dry infrastructure, but it's the difference between a fragile prompt pipeline and a solid one.

    Installing it

    Ships with Plush-for-ComfyUI. Install through ComfyUI Manager (search "Plush", install Plush-for-ComfyUI, restart), or clone it manually: cd ComfyUI/custom_nodes && git clone https://github.com/glibsonoran/Plush-for-ComfyUI.git, then pip install -r requirements.txt, restart.

    Common issues

    The number-one failure is that the model didn't actually return valid JSON. LLMs love to wrap JSON in prose ("Sure! Here's your JSON: ...") or fence it in markdown backticks, and that breaks a strict parse. The fix is upstream: force real JSON output with the Add Parameters response_format trick, and instruct the model to reply with JSON only, no preamble. The second issue is a key that doesn't match, which comes back empty; keys are exact, so Style and style are different. Check your model's actual output against the keys you typed. When a parse fails, the Troubleshooting output tells you what it choked on.

    CategoryPlush🧸/Utils

    Inputs (6)

    NameTypeDefaultDescription
    key_1STRINGJSON key whose value will be output
    key_2STRINGJSON key whose value will be output
    key_3STRINGJSON key whose value will be output
    key_4STRINGJSON key whose value will be output
    key_5STRINGJSON key whose value will be output
    json_stringoptSTRING

    Outputs (8)

    NameTypeDescription
    string_1STRING
    string_2STRING
    string_3STRING
    string_4STRING
    string_5STRING
    JSON_ObjDICTIONARY
    helpSTRING
    TroubleshootingSTRING