Nodes/ComfyUI-JMESPath/JMESPath ~πŸ…–
ComfyUI Node

JMESPath ~πŸ…–

Run JMESPath queries on JSON in the middle of your workflow

By gremlationΒ·Created 2 years agoΒ·Updated about a year agoΒ· 1
JMESPath ~πŸ…–
    • any
    • string
    • int
    • float
    β—„json_stringβ€”β–Ί
    β—„expression@β–Ί

    Every once in a while a workflow hands you a blob of JSON and you just need one value out of it - a URL from an API response, a number from a webhook payload, a field from ComfyUI's own API output. ComfyUI has no built-in node that parses JSON mid-graph. This one plugs that hole: feed it a JSON string, give it a JMESPath query, and it hands back exactly the piece you asked for. No API keys, no models, no GPU work. It's the smallest possible tool for a real, recurring pain.

    JMESPath is a query language for JSON - think of it as jq for people who'd rather not shell out to a subprocess, or as CSS selectors for data instead of HTML. If you've ever used the AWS CLI you've used it; it's the --query syntax there. A query like data.images[0].url walks into the data object, grabs the first element of images, and pulls its url. The default expression is @, which just returns the whole input unchanged - useful as a pass-through when you're chaining JSON nodes.

    The mechanism is exactly what you'd hope and nothing more. The node calls jmespath.search(expression, json.loads(json_string)) - the same jmespath library that powers AWS tooling, in its jmespath-community fork because the original PyPI package has been effectively frozen for years. One tiny dependency, zero downloads, no install surprises.

    Two inputs, both required, and neither is confusing:

    • json_string - the JSON text to query. It has defaultInput: true, so it'll happily take a wire from another node's output.
    • expression - your JMESPath query. Defaults to @.

    The output side is the clever part. There are four outputs, all showing the same result in different clothes: any (the raw result in its native type), string (always a string), and int and float (best-effort numeric casts). If the value can't convert to a number - say it's "hello" - the int and float outputs come back as None instead of erroring. That's the design working for you: wire the type your downstream node demands, and don't worry about the ones you don't use.

    Where people get burned, in descending order of likelihood:

    • The input isn't valid JSON. json.loads is unforgiving - a trailing comma or a single-quoted string kills the node with a hard error. If you're pasting a log line or a snippet, validate it first.
    • You learned jq, not JMESPath. The syntax is close but not identical: root access is bare foo.bar or @, not $.foo; string literals need backtick quoting; and projections ([]) behave differently from jq's .[]. A quick check against the JMESPath tutorial saves ten minutes of staring at a parse error.
    • You wired the int output and got None. If the value was a quoted string like "3", the int output still works (it coerces), but a genuinely non-numeric value yields None - which silently propagates downstream. Grab the string output instead.

    Installation is as painless as this pack gets. In ComfyUI Manager, pick Custom Nodes Manager, search for "ComfyUI-JMESPath", install, restart. Or via the CLI: comfy node install comfyui-jmespath. Manual install works the same way as any custom node:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Gremlation/ComfyUI-JMESPath
    pip install -r ComfyUI-JMESPath/requirements.txt
    

    Then restart ComfyUI. You'll find "JMESPath ~πŸ…–" under utils. It's a niche tool - you'll reach for it on the one workflow in ten that shuffles JSON around, and on that day it'll save you a detour through a text editor. That's about all there is to it, and that's fine.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    json_stringSTRINGβ€”
    expressionSTRING@β€”

    Outputs (4)

    NameTypeDescription
    any*β€”
    stringSTRINGβ€”
    intINTβ€”
    floatFLOATβ€”