Nodes/comfyui-sg-nodes/Find JSON Element
ComfyUI Node

Find JSON Element

Find the One Object in a List That Matches

By sebagallo·Created 9 months ago·Updated 6 months ago· 0
Find JSON Element
    • JSON_ELEMENT
    json_array[]
    match_key
    match_value

    An API returns a list of jobs and you want the one with a specific ID. Or a service returns several model options and you want the one whose name matches. Find JSON Element is the "grep the list" node: it scans a JSON array, finds the first element where a given key equals a given value, and returns that whole element as a JSON string.

    It slots in right after the other JSON utilities in this pack. Poll a remote service with Poll Remote URL, get a list back in RESPONSE_BODY, feed it here to pluck out the entry you care about, then hand the result to Map JSON To Property to extract the field you actually want. Three nodes, and you've built a mini query against any external service.

    Inputs

    • json_array - the array to search, as a JSON string.
    • match_key - the key to check in each element. Dot notation works: status.code reaches nested keys, and the same array-indexing trick from the other JSON nodes applies.
    • match_value - the value to match. It's compared as a string, so 1 and "1" both match a numeric 1, and true matches a boolean true. Loose, but usually exactly what you want.

    One output: JSON_ELEMENT - the matching element serialized back to a JSON string (so you can chain it into more JSON nodes). If nothing matches, you get an empty string, not an error.

    How it decides

    The comparison is str(found_value) == str(match_value), and it returns the first hit in array order. Two practical consequences. First, ordering matters - it's "first match," so sort your input upstream if the array order isn't what you expect. Second, an empty output means no element matched, which is indistinguishable from "the array was empty or invalid" - both give you "". If you're getting nothing back, preview the raw json_array first and check whether the key path or the value's string form is off.

    It's a small, boring, useful node. That's the whole review. If you're building anything that talks to a JSON API inside ComfyUI, the three-node JSON trio in this pack (Map JSON To Property, Map JSON Array, Find JSON Element) covers most of the parsing you'll ever need, and this is the filter in the middle.

    Install

    Part of comfyui-sg-nodes by sebagallo. ComfyUI Manager → search comfyui-sg-nodes, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sebagallo/comfyui-sg-nodes
    

    Restart ComfyUI; it's under SGNodes/JSON. No model downloads, no extra pip packages.

    CategorySGNodes/JSON

    Inputs (3)

    NameTypeDefaultDescription
    json_arraySTRING[]JSON array string.
    match_keySTRINGThe key to check in each element. Supports dot notation.
    match_valueSTRINGThe value to match against (compared as string).

    Outputs (1)

    NameTypeDescription
    JSON_ELEMENTSTRING