Nodes/ZMG PLUGIN/JSON解析器
ComfyUI Node

JSON解析器

Dig any value out of a JSON response without a regex prayer

By fq393·Created 2 years ago·Updated 7 months ago· 8
JSON解析器
    • result
    • path_info
    input_typejson
    input_string
    json_path
    output_formatstring
    default_value

    The natural counterpart to the pack's API Request Node. That node hands you a JSON response as a big string; this one lets you reach inside and pull out exactly the field you care about. Want the url from a data.items[2].files[0] blob? Type a path, get a value. It's the difference between staring at a wall of JSON and actually using it.

    How it works

    It parses the input as JSON, then walks a path you provide. The path syntax is the friendly kind: dot-separated keys plus bracket indexing - data.items[0].name style, no jsonpath library to learn. It also supports input_type: "string" if you want it to just pass a plain string through untouched (a useful escape hatch when the input might not be JSON at all).

    The path walker handles nested objects and array indexes with bounds checking. If a key is missing or an index is out of range, it falls back to default_value (or returns an empty string) and tells you exactly where the path failed in a second output - so you get "key 'files' does not exist at path data.items[0].files", not a silent empty result.

    Inputs that matter

    • input_string - the JSON to parse. Multiline, so you can paste a whole response or wire it from an API node.
    • json_path - e.g. data.items[0].name. Leave blank to return the entire JSON.
    • output_format - string (default, plain text), json (compact), or pretty_json (indented). Pick json when the extracted value is itself an object you're passing on.
    • default_value - what you get back when the path doesn't resolve.
    • input_type - json (parse it) or string (return as-is).

    Outputs

    result is your extracted value as a string; path_info is a human-readable status line - "成功提取路径: ..." or a precise failure message, plus whether a default was used. path_info is genuinely useful for debugging, and since the node returns errors as strings rather than throwing, you can wire it into a display and see what went wrong in the UI.

    Pairing it

    A typical mini-pipeline: API Request → JSON Parser with path data.url → whatever you actually wanted. Or JSON Parser → JSON Builder's merge_json for building new payloads out of pieces of old ones. The string result output means nearly everything downstream can consume it.

    Installing

    Ships in the ZMG pack. ComfyUI Manager → search "ZMG" / "ComfyUI-ZMG-Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/vanche1212/ComfyUI-ZMG-Nodes
    cd ComfyUI-ZMG-Nodes
    pip install -r requirements.txt
    

    Restart, and it appears under ZMGNodes/data. No dependencies beyond the pack's base set - just Python's built-in json module doing the work. If your JSON is malformed, it won't crash the graph; it returns a descriptive error in result and moves on, which is the right failure mode for a data node in the middle of a pipeline.

    CategoryZMGNodes/data

    Inputs (5)

    NameTypeDefaultDescription
    input_typeCOMBOjson2 options: json, string
    input_stringSTRING
    json_pathSTRING
    output_formatCOMBOstring3 options: string, json, pretty_json
    default_valueSTRING

    Outputs (2)

    NameTypeDescription
    resultSTRING
    path_infoSTRING