Nodes/ComfyUI-XJNodes/JSON Extractor
ComfyUI Node

JSON Extractor

Pull one value out of a JSON blob without a regex in sight

By alexjx·Created 10 months ago·Updated 4 months ago· 0
JSON Extractor
    • string
    • float
    • int
    • boolean
    json_string
    key_path

    ComfyUI workflows are JSON. Generated images carry their workflows as embedded metadata, which is JSON inside the PNG. API responses from image models are JSON. And yet, in a graph editor, JSON has historically meant "paste a blob into a text node and squint." JSON Extractor is the node that ends that: you feed it a JSON string and a dotted key path, and it walks the structure and returns the value - in four formats at once.

    The README's own pitch is parsing metadata, and that's the workflow that sells it. You load an image that has a workflow embedded, extract the JSON (the pack's Load Image With Metadata does this natively), and then workflow.settings.cfg or nodes.3.seed becomes a live value you can wire straight into a KSampler. One loaded image, and your graph re-derives the settings that made it.

    How it works

    It parses the JSON, then walks the key_path dot-notation: workflow.settings.cfg means dig into workflow, then settings, then grab cfg. The path language is small but genuinely useful:

    • Object keys - prompt.something
    • Array indices - nodes.0.seed reaches into the first element of a list
    • Nested paths - data.items.2.name
    • Nested JSON strings - if a field's value is itself a JSON string and more of the path remains, it parses it on the fly. This is the trick that makes embedded-workflow metadata work, because that metadata is often a JSON string inside the JSON

    Once it finds the value, it converts it to all four types: string, float, int (handles "7.5" → 7 via float), and boolean. Missing paths and failed conversions return None on that output rather than erroring, which is friendly for graphs - the node won't crash a run just because a key wasn't there.

    Inputs and outputs

    • json_string - the JSON text, wired in (forceInput), not typed
    • key_path - the dotted path, e.g. workflow.settings.cfg or nodes.0.seed

    Four outputs, one per type: string, float, int, boolean. Take whichever you need and ignore the rest - they're all the same value, just coerced. Wiring the int output into a seed or step input and the string output into a prompt port is the intended pattern.

    Installing it

    One node in the XJNodes pack. ComfyUI Manager → search "ComfyUI-XJNodes" → install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alexjx/ComfyUI-XJNodes
    # restart ComfyUI
    

    It uses Python's stdlib json (plus a small compatibility shim for tolerant parsing), so no extra packages. Category: XJNodes/text.

    Where it gets fiddly

    The failure mode to learn: a path that doesn't exist doesn't raise, it silently returns None. So a typo like workflow.setting.cfg looks fine until the value doesn't flow. If a node downstream suddenly receives None, check the path before suspecting the wiring. Also, _to_bool uses Python truthiness - the string "false" converts to True because it's a non-empty string, which will absolutely bite you if you're extracting booleans from JSON. For numbers and strings it's a workhorse; for booleans, verify the output once. If you're feeding values from an API response rather than embedded workflow metadata, the same rules apply - and honestly, this node is the rare utility in a personal-use pack that deserves a permanent spot in your toolset.

    CategoryXJNodes/text

    Inputs (2)

    NameTypeDefaultDescription
    json_stringSTRING
    key_pathSTRING

    Outputs (4)

    NameTypeDescription
    stringSTRING
    floatFLOAT
    intINT
    booleanBOOLEAN