PD_CaptionJSON解析器
Pull the caption out of a JSON blob
- caption
- lang
PD_CaptionJSON解析器 (PD_CaptionJSONParser) is the read half of the pack's JSON-caption pair. Feed it a JSON string with caption and lang fields and it hands you those two values as separate outputs. That's the whole job: parse, split, done.
Why it exists
More and more captioning tools and dataset pipelines are storing captions as structured JSON - {"caption": "...", "lang": "en"} - instead of a bare text file. That's nice for the tool that writes them and mildly annoying for everything else, because a CLIP Text Encode or a training-prep node wants plain text. This node is the bridge. And because it outputs a list when fed a list, it plays cleanly with the pack's folder-loading nodes: load a batch of JSON caption files, parse them all in one run, and wire the caption output straight into whatever needs the raw text.
How it works
It parses the input with Python's json module and pulls out the caption and lang keys. If parsing fails, it degrades to treating the raw string as the caption with lang defaulting to en - the same forgiving fallback as its editor sibling, which means a malformed blob won't crash your workflow but also won't be flagged. Both outputs are declared as lists, so a single string comes through as a one-element list; if a downstream node chokes on that, a string-from-list node sorts it out.
Inputs and output
json_string- the JSON to parse (required, multiline, wireable).- Outputs:
caption- the extracted caption text;lang- the language field.
Nothing else. No options, no modes. That's the appeal: it's a tiny deterministic adapter, not a feature.
Installing
Part of the 7BEII/Comfyui_PDuse pack. ComfyUI Manager → search "Comfyui_PDuse" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart after. No models, no extra dependencies beyond the pack's standard install.
Gotchas
Know your input format. If your JSON uses a different shape - say {"text": "..."} or a nested structure - this node won't find it, because it looks specifically for caption and lang. And remember the silent-fallback behavior: a badly-formed input becomes the caption verbatim, which can smuggle JSON syntax into your prompt text if you're not watching. For anything fancier, the editor variant (PD_CaptionJSONEditor) is the one with the editing tools; this one is strictly a two-output parse.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| json_string | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| caption | STRING | — |
| lang | STRING | — |