Nodes/ComfyUI-JK-TextTools/Query Detection JSON
ComfyUI Node

Query Detection JSON

Filter detection JSON like a pro — wildcards, score thresholds, and bbox lists

By Nakamura2828·Created 8 months ago·Updated 8 months ago· 0
Query Detection JSON
    • filtered_json
    • match_count
    • detection_list
    • bbox_list
    • categorization_value
    • is_valid
    • error_message
    json_string[]
    class_filter*
    min_score0.00
    max_results0
    categorization_field

    Detection Query is the front door of this pack's detection side. Detector models - GroundingDINO, YOLO variants, classification pipelines - dump results as JSON, and that JSON is usually a mess of everything the model found, confident or not, in every class. This node filters that blob down to what you actually care about and, crucially, hands you the matching bounding boxes as a proper list.

    The one-step value: a raw detection JSON goes in, and out comes bbox_list - a list of BBOX objects you can wire straight into the pack's BBoxes to Mask (or anywhere else that eats bboxes). No manual JSON spelunking, no regex, no "which key holds the box again?" moments.

    How it works

    It parses the JSON and understands the common shapes: a plain list of detection dicts, or a wrapper like {"detect_result": [...]} (the format a lot of detectors emit). Each detection is expected to have a class and a score. Then it filters:

    • Class filter with wildcards (fnmatch-style): DOG matches exactly, DOG_* matches all DOG subclasses, *_LABEL matches anything ending in _LABEL, * matches everything.
    • min_score (FLOAT, 0–1) - drops low-confidence detections.
    • max_results (INT, 0 = unlimited) - caps how many come back.
    • categorization_field - if set, extracts that field from the root object and passes it out separately.

    Outputs: filtered_json (STRING), match_count (INT), detection_list (list - individual detection objects, grid icon), bbox_list (list of BBOX), categorization_value (*), plus is_valid (BOOLEAN) and error_message (STRING) for when the JSON doesn't parse.

    Inputs that matter

    • json_string (STRING, multiline) - the detection JSON.
    • class_filter (STRING, default *) - your wildcard pattern.
    • min_score, max_results, categorization_field - the optional dials.

    Where it fits

    The pack's own example: class_filter: "DOG_*", min_score: 0.7bbox_list → BBoxes to Mask → one combined mask of every confident dog, plus individual masks per dog. And because detection_list is a list output, you can iterate it and hand each detection to Detection to BBox for per-object x/y/w/h and class/score.

    Installing it

    It's part of ComfyUI-JK-TextTools. ComfyUI Manager → search "JK-TextTools" → install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Nakamura2828/ComfyUI-JK-TextTools.git
    

    Restart ComfyUI. No models, no runtime pip deps beyond ComfyUI.

    Gotchas

    The expected schema is fixed: detections must be dicts with class and score, and it looks for the box under box (or bbox) when building bbox_list - if your source names them differently, you'll get matches with match_count correct but empty boxes. Invalid JSON doesn't crash; it sets is_valid false and fills error_message, which is your debugging breadcrumb. And max_results 0 meaning "unlimited" is easy to forget if you set it expecting zero results.

    CategoryJK-TextTools/json

    Inputs (5)

    NameTypeDefaultDescription
    json_stringSTRING[]
    class_filterSTRING*
    min_scoreoptFLOAT0.000–1
    max_resultsoptINT00–1000
    categorization_fieldoptSTRING

    Outputs (7)

    NameTypeDescription
    filtered_jsonSTRING
    match_countINT
    detection_list*
    bbox_listBBOX
    categorization_value*
    is_validBOOLEAN
    error_messageSTRING