ComfyUI Node

Apex JSON Lookup

Dig one field out of a JSON blob without leaving ComfyUI

By ApexArtist·Created about a year ago·Updated 22 days ago· 5
Apex JSON Lookup
    • value
    ◄text►
    ◄key►

    Somewhere upstream of you, a node is about to hand the graph a JSON blob instead of a prompt - because an LLM answered in prose with an object stuck in the middle of it ("Here is your prompt: {...}"), or an API wrapper returned a payload with fields you don't want, or you pasted a chunk of someone's workflow JSON into a box to see what was in it.

    Apex JSON Lookup is the node that turns that blob back into a plain string. Two inputs, one output, no branching logic, no parsing language to learn.

    What it is, and when to reach for it

    Set text to the JSON (or paste it), set key to the field you want, and the value output gives you that field as a STRING. Wire it into a CLIP Text Encode and the JSON disappears from your prompt.

    This is plumbing, and it's the kind the ecosystem quietly lacked for years. The node layer between the model and the pixels - the text and value nodes that shuffle data around - is the least documented part of ComfyUI, and people end up hand-rolling string surgery with whatever they have. The specific trigger: LLM and API nodes hand you structured text and almost nothing to parse it with. Ask an LLM for JSON and it replies with chat scaffolding wrapped around the object; an API wrapper returns a payload, not a prompt.

    How it works

    It tries the clean path first. json.loads on your text; if that parses, it walks your key by splitting on dots - a dictionary key at each step, or a digit treated as a list index. So data.0.caption means the data key, the first item of that list, then caption. A value that is itself an object or array gets re-serialised as a JSON string rather than becoming [object Object], which is genuinely handy for metadata-style fields.

    If parsing fails - malformed JSON, truncated JSON, or an LLM that wrapped the object in a sentence - it falls back to a regex hunt for "key": and grabs what follows, stopping at a comma, a line break or a closing brace, and stripping the surrounding quotes. That fallback is why the node tolerates the "Sure! Here's the JSON:" case that breaks a strict parser, and it's also the source of its one real footgun (below).

    And the text doesn't have to be one clean document - paste a PNG's embedded workflow JSON in there and paths like 4.inputs.text are in scope.

    Inputs and outputs

    • text (multiline STRING) - the JSON, or the prose that has JSON in it.
    • key (STRING) - the field name or dotted path. Empty key returns an empty string.

    One output: value (STRING). Convert the text widget on your CLIP Text Encode to an input (right-click → Convert widget to input) and wire this into it. Put a text display node in the middle if you want to see what came out - you'll want one the first time something doesn't work.

    Install

    Same pack, same two moves. Manager: search Apex Artist (the listing shows up under the pack title Apex Artist - Image Resize too). Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ApexArtist/comfyui-apex-artist.git
    pip install -r comfyui-apex-artist/requirements.txt
    

    Restart ComfyUI afterwards. There's nothing to download and no model to load - this node is standard-library Python. Install the pack just for this node if you like, but you'll also get a blur/sharpen/blend toolkit, a LoRA browser, a prompt-preset system and an HDRI viewer. None of it loads until it's in a graph, and the only third-party dependency is opencv-python, so it's a cheap install.

    Where people get burned

    A missing key is silent. No error, no warning, just an empty string in the value socket - and an empty string into a CLIP Text Encode gives you a perfectly valid generation of nothing in particular. When an image comes out mushy and generic, check here before you touch the sampler.

    The regex fallback grabs the first match, not the right one. If your text contains "caption" twice and the clean parse failed, you get whichever appears first. Prefer valid JSON upstream; the fallback is a safety net, not a feature.

    Keys with dots in them aren't addressable. The path splitter treats every . as a level, so meta.prompt.text means three levels down, never a key literally called prompt.text. Digits are analogous: a numeric key works in a dictionary, but in a list it's an index.

    It's a lookup, not a template. One key, one value; merging three fields into one prompt is a string concat node's job.

    CategoryApex Artist/Text

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING—
    keySTRING—

    Outputs (1)

    NameTypeDescription
    valueSTRING—