Query Detection JSON
Filter detection JSON like a pro — wildcards, score thresholds, and bbox lists
- filtered_json
- match_count
- detection_list
- bbox_list
- categorization_value
- is_valid
- error_message
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):
DOGmatches exactly,DOG_*matches all DOG subclasses,*_LABELmatches 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.7 → bbox_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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| json_string | STRING | [] | — |
| class_filter | STRING | * | — |
| min_scoreopt | FLOAT | 0.000–1 | — |
| max_resultsopt | INT | 00–1000 | — |
| categorization_fieldopt | STRING | — |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| filtered_json | STRING | — |
| match_count | INT | — |
| detection_list | * | — |
| bbox_list | BBOX | — |
| categorization_value | * | — |
| is_valid | BOOLEAN | — |
| error_message | STRING | — |