Nodes/VLM_nodes/JSON Extract
ComfyUI Node Runs on cloud

JSON Extract

Your VLM answered inside a JSON blob five levels deep. Dig it out.

By gokayfem·Created 3 years ago·Updated 9 days ago· 583
JSON Extract
    • value
    • found
    • value_type
    • canonical_json
    text{}
    path$
    output_formatText
    if_missingError
    default_value

    Ask a modern VLM to return structured data and it will - wrapped in a JSON object nested three levels deep, possibly inside markdown fences, with the one field you actually need buried at $.result.items[0].value. JSON Extract is the pack's safe way to pull that field out without writing a regex or installing a scripting node.

    It's part of the text toolkit in gokayfem's VLM_nodes pack - the dependency-free string/JSON utilities the pack ships so you can shape a model response without bolting on another custom-node pack. And "safe" is doing real work here: the implementation never evaluates code, follows references, or touches the filesystem. You give it JSON, it reads JSON.

    How it works

    You feed it text (plain or fenced JSON - it strips the fences for you), a path, and it resolves the path in one of two syntaxes:

    • JSONPath-lite: $.result.items[0] - dot access with numeric indexes.
    • RFC 6901 JSON Pointer: /result/items/0 - the standard pointer syntax.

    It returns the value plus a found boolean and value_type (string, number, boolean, null, array, object...), and a canonical_json output with the cleaned-up document. output_format controls how the extracted value is rendered - Text for a plain value, or compact/pretty JSON when the value is itself a nested structure.

    if_missing decides what happens when the path doesn't resolve: raise an error (the default), return an empty string, or return your default_value. For automation, the "Empty string" or "Default value" modes are usually the right call - a missing field shouldn't kill the whole queue.

    Inputs and outputs

    • text (STRING, multiline) - the JSON document (fences OK).
    • path - $.dot[0] or /pointer syntax.
    • output_format - Text / Compact JSON / Pretty JSON.
    • if_missing / default_value - the missing-field policy.

    Outputs: value, found, value_type, canonical_json.

    Installing this pack

    Same install as every node in this pack. ComfyUI Manager: search VLM_nodes. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gokayfem/ComfyUI_VLM_nodes
    cd ComfyUI_VLM_nodes
    python -m pip install -r requirements.txt
    

    Run pip with ComfyUI's Python. This node has zero model downloads and no heavy deps - it's pure text handling.

    Common issues

    Path syntax is the classic stumble: $.items[0] uses a leading $, and JSON Pointer /items/0 starts with a slash and uses forward slashes, not dots - mixing the two gets you "path not found." If you're extracting from a VLM response that wrapped JSON in json ``` fences, no problem - it strips those. One more: keys with special characters like spaces or dots won't resolve cleanly in the JSONPath-lite syntax; the JSON Pointer form handles those better, which is why the node supports both.

    CategoryVLM Nodes/Text/JSON

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING{}
    pathSTRING$
    output_formatCOMBOText3 options: Text, Compact JSON, Pretty JSON
    if_missingCOMBOError3 options: Error, Empty string, Default value
    default_valueSTRING

    Outputs (4)

    NameTypeDescription
    valueSTRING
    foundBOOLEAN
    value_typeSTRING
    canonical_jsonSTRING