ComfyUI Node

JSON Parser

Querying JSON inside ComfyUI with JSONata

By TinyBeeman·Created about a year ago·Updated about a month ago· 1
JSON Parser
    • result
    json
    jsonata$
    stripQuotestrue
    seed0

    JSON Parser is the node that finally lets you query JSON instead of just pasting it around. It parses a JSON string and evaluates a JSONata expression against it - JSONata being a proper query language, closer to a grown-up jq than to a regex hunt. Feed it an API response and $.data.items[0].name pops out the field you wanted.

    Why you'd reach for it

    ComfyUI workflows increasingly touch JSON: API responses, config files, the metadata blob from Load Image w/Meta, batch metadata from the zip loader. Without a query node you're stuck doing string surgery or building a tangle of Search and Replace nodes. This node gives you real expressions - path lookups, array filtering, transforms - and returns a string you can feed anywhere.

    How it works

    Under the hood it uses jsonata-python, the Python port of the JSONata engine. Your JSON gets parsed with json.loads, then the jsonata expression is evaluated against it. The default expression is $ which returns the whole document - handy for validation or pass-through.

    Two extras worth knowing. The seed input powers two registered functions, srnd (a seeded random number) and sshuffle (a seeded shuffle), so you can randomize data inside a query reproducibly. And stripQuotes (on by default) removes the surrounding quote characters from string results - so a plain string result comes back as the bare text, and escape sequences like \n come through as real newlines rather than literal backslash-n.

    The inputs that matter

    • json - the multiline text box with your JSON document.
    • jsonata - the query expression. Default $ = whole document. This is where you'll spend your time learning JSONata syntax.
    • stripQuotes - on by default; turn off if you want the raw JSON-quoted string.
    • seed - feeds the srnd/sshuffle functions in queries. Not the source of general randomness.

    One output:

    • result - the evaluated result as a STRING.

    Installing it

    This is the one node in the pack with a real dependency. The pack's README claims everything is standard library, but that's stale - the code needs jsonata-python, and the node raises jsonata is not installed. Run: pip install jsonata if it's missing. Install the pack via ComfyUI Manager (search "ComfyUI-TinyBee") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
    pip install jsonata
    

    Then restart ComfyUI. It's under 🐝TinyBee/Strings.

    Common issues

    Two failure modes dominate. First: no jsonata installed → the node errors at runtime; fix it with pip install jsonata and restart. Second: malformed JSON → JSON parse error, usually because you pasted text with literal newlines inside string values (run it through Json Input first to clean those up). If your expression errors, it'll say JSONata error: with the engine's message - JSONata syntax is its own thing, so expect a learning curve on expressions like $filter(items, function($v) $v.active).

    Category🐝TinyBee/Strings

    Inputs (4)

    NameTypeDefaultDescription
    jsonSTRING
    jsonataSTRING$
    stripQuotesBOOLEANtrue
    seedINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    resultSTRING