ComfyUI Node

TG Parse JSON ◀️

The two-node bridge between a text box and an API call

By CoolBreeze164·Created 13 days ago·Updated 2 days ago· 3
TG Parse JSON ◀️
    • DICT
    ◄json_string—►

    The smallest node in the pack, and the one that makes the other small node useful. TG API Method wants a DICT of parameters. A text box gives you a STRING. This node is json.loads with a socket on each end.

    What it does

    You feed it a json_string (multiline), it returns a DICT. That's the whole node - no schema, no validation beyond what json.loads does. It's kept from the original SwissCore92 pack the sender family was adapted from, filed under Autonomous Telegram Bot ◀️/experimental, and it exists specifically as the companion to API Method.

    The practical wiring is:

    text (JSON) → TG Parse JSON → DICT → TG API Method (params)
    

    So a getMe check is just {"chat_id": -1001234567890}-style JSON in a text widget, parsed, and handed to the method call. For richer calls you can nest freely, because API Method's transport JSON-encodes dicts, lists and booleans for you and drops None values:

    {
      "commands": [
        {"command": "image", "description": "generate a picture"},
        {"command": "reset", "description": "clear my session"}
      ],
      "scope": {"type": "all_private_chats"}
    }
    

    Note what that buys you that a plain string can't: Telegram's API has genuinely nested parameters (commands, media, scope) and a flat key/value form would make them impossible.

    Where it goes wrong

    The input is a STRING, so it has to be valid JSON - double quotes, no trailing commas, no Python dict syntax with single quotes, no comments. Invalid JSON raises out of the node as an execution error, and this pack doesn't retry its way past a syntax error. In practice the usual culprit is pasting a Python dict out of a script or dropping a comma while editing a long blob.

    Second gotcha: keep the top level an object. json.loads("42") is perfectly valid JSON and this node will happily return a number, but API Method then tries to treat it as a dictionary of parameters and fails. Curly braces, always.

    Third: this node doesn't inject anything. It won't merge your chat_id into the params - API Method's own chat_id socket does that, and it takes precedence in the sense that it's written into the param dict before the request goes out. If you put a chat_id in the JSON and wire the socket, you're writing the same key twice and the socket wins.

    And the usual caveat: JSON you type into a widget lives in the workflow JSON when you save. If it contains a bot token, that token is in the file.

    Install

    It ships in the same pack, so:

    cd ComfyUI/custom_nodes
    git clone https://github.com/CoolBreeze164/ComfyUI-Autonomous-Telegram-Bot
    python -m pip install -r ComfyUI-Autonomous-Telegram-Bot/requirements.txt
    

    python_embeded\python.exe for the pip line on Windows portable. The pack's deps (httpx, numpy, pillow, av>=14.2.0) are irrelevant to this node - it's pure standard library - but installing them keeps the rest of the pack working. Or use ComfyUI Manager and search ComfyUI Autonomous Telegram Bot, then restart.

    When you'd skip it

    If you're only ever sending text and images, you will never open this node, and that's fine - plenty of bot workflows consist of a Listener and two senders. Reach for it the first time you want a Telegram call the pack doesn't have a node for. The pair (Parse JSON → API Method) is the plugin system for this pack, and it's the honest answer to "but what about this Bot API method?"

    CategoryAutonomous Telegram Bot ◀️/experimental

    Inputs (1)

    NameTypeDefaultDescription
    json_stringSTRING—

    Outputs (1)

    NameTypeDescription
    DICTDICT—