ComfyUI Node

Json Parser

Unwrap a pile of JSON into the one field you need

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
Json Parser
    • STRING
    json_text
    modeauto
    path
    extract_key_names
    array_index-1
    key_filter
    value_filter
    flatten_separator.
    output_modelist
    join_separator,

    Every workflow that talks to an API or an LLM eventually dumps a blob of JSON on you, and somewhere in that blob is the one field you actually care about. JsonParser is the shovel. It's the biggest, most flexible node in the wwdm-aicd pack, and it's the answer to the most common question after "how do I get text out of an LLM" - which is "how do I get one field out of the JSON the LLM gave me."

    The node takes json_text (a plain string, multiline) and has eight modes. Start with the ones that match the shape of your data. path walks a dotted/bracketed path like data.users[0].name - the code splits on dots and brackets, so that syntax just works. extract_keys is the one the README calls out as recommended: give it extract_key_names as a comma-separated list ("中文提示词,age") and it recursively hunts for any object key with that name at any depth, pulling every value it finds. That's the killer feature - you don't need to know the JSON structure, just the key you want. keys lists every key with its path, values grabs every leaf value, array_items extracts array elements (with array_index for "give me element 2"), flatten turns nested objects into user.name: 张三 lines with a configurable flatten_separator, and auto dumps the top-level values.

    Then there's query, which is a mini query language. In path you write age>25 and it filters a list of objects by that condition, returning the matching objects. Supported operators: ==, !=, >, <, >=, <=, plus contains, starts, ends. It's not MongoDB, but for "give me everyone over 25" it does the job, and it tries numeric comparison before falling back to string comparison, which is the right call.

    Output is a STRING list, and output_mode can flip it to a single joined string with join_separator (default comma). It drops straight into TxtRegSelect or ListOps for further narrowing, or into an LLM node's prompt field. A typical chain: AIChatAPI returns JSON → JsonParser with extract_keys pulls the one field → TextTrim cleans it → done.

    Mechanically it's json.loads under the hood, and it fails softly: if the JSON won't parse, you get an empty list rather than a node crash. That's friendly, but it's also the trap - a wrong mode with bad JSON silently gives you nothing. If the output's empty, first question: is the JSON actually valid? Second: does that key exist? Also note the whole thing is string-typed end to end; numbers come out as their string representation, so if you need arithmetic on a parsed value, route it through a node that can convert first.

    Install is the standard story for this pack, which is pure Python with no model downloads:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI and it's under the wwdm-aicd category. Ignore the README's pip install -r requirements.txt - there's no requirements.txt in the repo; everything here is stdlib. README and source comments are in Chinese. The pack is brand new and effectively unknown, so expect a small surface and no community lore - which is fine, because the source is short enough to read if a mode surprises you. JsonParser is the half of the JSON pair you'll reach for constantly; JsonBuilder is the other half, and this one is the better of the two.

    Categorywwdm-aicd

    Inputs (10)

    NameTypeDefaultDescription
    json_textSTRING
    modeCOMBOauto8 options: auto, path, keys, values, extract_keys, array_items, +2
    pathSTRING
    extract_key_namesoptSTRING
    array_indexoptINT-1
    key_filteroptSTRING
    value_filteroptSTRING
    flatten_separatoroptSTRING.
    output_modeoptCOMBOlist2 options: list, join
    join_separatoroptSTRING,

    Outputs (1)

    NameTypeDescription
    STRINGSTRING