Nodes/honda-nodes/πŸ“‘ JSON Validate
ComfyUI Node

πŸ“‘ JSON Validate

The cheap guard that stops a broken blob failing your save

By AvarayΒ·Created 14 days agoΒ·Updated 12 days agoΒ· 0
πŸ“‘ JSON Validate
    • Is Valid
    β—„json_data{}β–Ί

    This is the least glamorous node in the pack and the one I'd add to a pipeline first. Once you start moving JSON strings around between nodes - pulling metadata off an image, merging in your own fields, handing the result to something that writes it into a file - a single bad character stops being a cosmetic annoyance and starts being a failed run in the middle of a 200-image batch. JSON Validate answers "is this string parseable?" and nothing else.

    How it works

    No jq, no subprocess. It's json.loads in a try/except: if the string parses, the boolean is true; if ValueError comes back, it's false. Whitespace-only or empty input counts as false - a deliberate call, since the empty string isn't JSON and the node defaults to {} only as a widget value.

    Because it's Python's parser and not jq's, "valid" means exactly what json.loads accepts. That has one consequence worth internalising: top-level scalars are valid. 42, "hello", true and null all return true, because JSON's grammar allows a bare value at the root. If you actually need "is this a JSON object I can set keys on", this node won't tell you - it'll say yes to 42 and then JSON Set Key will fail in a way that's harder to read.

    The inputs and outputs that matter

    One input, JSON Data, and one output, Is Valid (BOOLEAN).

    The input is a forced input, which is the thing that trips people up: you can't type or paste into it, you have to wire a STRING in. Drop a Text node next to it if you're testing a literal, or take the upstream string straight from Read File / Load Image's Metadata / JSON Merge.

    What do you do with a boolean in ComfyUI? Not much natively - there's no core If node that reroutes a graph on a boolean. In practice you use it as a gate and a signal: wire it to the pack's own switch/logic nodes if you have them, or more realistically send it to Print to Console so the value shows up in the server log, and pair it with Text Preview to eyeball the failing string in the same run. It's a diagnostic, not a transformer - which is why it stays useful even when the rest of your JSON plumbing changes.

    The genuinely valuable placement is immediately upstream of a save. If Save Image is being handed a metadata string and that string isn't valid JSON, you get a warning in the console and a file with no metadata - the run "succeeds" and you find out an hour later that 200 images are blank inside. Putting Validate in front converts that silent loss into something you can see.

    How to install it

    Part of Avaray/honda-nodes - ComfyUI Manager β†’ Node Pack β†’ search Honda Nodes β†’ Install β†’ restart. Manual:

    cd ComfyUI/custom_nodes
    git clone --depth 1 https://github.com/Avaray/honda-nodes.git
    cd honda-nodes
    python install.py
    

    This specific node needs nothing from install.py (it's pure Python stdlib), but run it anyway - the pack's other JSON nodes and all the metadata/image nodes depend on the jq and ime binaries it downloads into bin/.

    Common issues

    It says invalid and the string looks fine. Invisible newlines from a multiline paste, a trailing comma before a closing brace, single quotes instead of double (classic if the JSON came from a Python print or a hand-edited file), or a BOM at the start of a file you read off disk. Text Preview the string and you'll usually spot it in the first line.

    It says invalid on a value you know is a string of text. Correct - the quick brown fox isn't JSON. A JSON string needs quotes: "the quick brown fox". That's the whole reason the pack's metadata pipeline is fussy about the shape of what it passes around.

    It says valid for NaN. Python's json.loads accepts NaN and Infinity as extensions by default, even though they aren't legal JSON - so a Python-produced blob can pass this check and still choke a strict consumer (the browser's JSON.parse, notably, which is why the pack's preview has to sanitise it). Worth remembering when something downstream rejects a string this node blessed.

    Category⚑️ Honda Nodes/πŸ“‘ JSON

    Inputs (1)

    NameTypeDefaultDescription
    json_dataSTRING{}The JSON string to validate.

    Outputs (1)

    NameTypeDescription
    Is ValidBOOLEANβ€”