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

jq ~πŸ…–

Query JSON inside your graph without leaving ComfyUI

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

    Every ComfyUI workflow is a JSON file - the graph, the node settings, the whole saved thing. And the moment you start feeding external data into ComfyUI, you hit a wall: an LLM node hands you structured JSON, an API returns a payload, a saved workflow needs a parameter pulled out of it. The graph has no built-in way to query JSON. You stare at a blob of text and think "I just want the seed out of this."

    That's exactly what this node is for. It's a tiny, boring, single-purpose utility that runs a jq query against a JSON string and hands you the result as typed outputs you can actually wire somewhere. No API, no key, no model download - the name is a lie in the good direction.

    How it works

    If you've ever worked with APIs, jq is that command-line tool you reach for to slice JSON into something usable. This node wraps the same jq engine (through the jq Python binding, which bundles jq's C code) inside a single ComfyUI node. The whole node is maybe fifteen lines of Python: it parses your JSON with json.loads, compiles your expression, runs it, and takes the first result. That's the entire mechanism, and it means anything jq can do - field extraction, array slicing, conditionals, transforms - works here too.

    The inputs and outputs that matter

    Only two inputs, both required:

    • json_string - the JSON you want to query. It's marked defaultInput, so you can wire it from anything that emits JSON text, or just paste JSON into the box.
    • expression - the jq filter. Default is ., which returns the input unchanged. Start there, then move to .["seed"] to grab a field, .data[0].prompt for nested paths, .[] to iterate a list. If you don't know jq's syntax yet, the manual is genuinely readable and you'll only need a third of it.

    Here's the part that makes this node useful rather than decorative: it has four outputs.

    • string - the result as text. The one you'll use for anything that isn't a number.
    • int and float - the result coerced to a number, ready to plug straight into a seed, a strength, or any INT/FLOAT input downstream. This is the big one: a JSON number becomes a usable graph value.
    • any - the raw parsed object (a dict or list if that's what jq returned). Mostly for eyeballing in the UI, since few nodes accept a wildcard ANY input.

    One gotcha baked into the design: int and float are None whenever the result can't be coerced to a number. Wire a None into an INT input and it errors. If your expression returns a string, use the string socket.

    Installing it

    The easy way is ComfyUI Manager: open Manager β†’ Custom Nodes Manager, search "ComfyUI-jq", install, restart. Or from a terminal:

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

    The entire dependency list is one line: the jq package. No model files, no torch, no heavy C toolchain - modern releases ship prebuilt wheels for Linux, macOS, and Windows, so install is quick. The only time it gets fiddly is an unusual platform where pip has to build from source, which needs a C compiler.

    Common issues

    • "Invalid JSON" errors. The input must be actual JSON - a plain sentence or a Python-style dict (single quotes) will fail. This node queries JSON; it's not a general text slicer.
    • Multiple results get truncated. jq filters like .[] can emit several values, but the node runs .first(), so you only ever see the first one. If you need all of them, structure the filter to return one aggregate - or accept the first.
    • Wiring None into a number input. As above - check your query is actually returning a number before you grab the int socket.

    Honest take: this is a niche node for a real gap. Most people will never need it. But the day you're plumbing an LLM's JSON output into your seed or batch size, you'll be glad it exists - it's one of those "why did this not exist" utilities that saves you from writing a Python script to do the same five-line job.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    json_stringSTRINGβ€”
    expressionSTRING.β€”

    Outputs (4)

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