Text to JSON
When a string of JSON needs to become data
- json_output
- error_message
Text to JSON parses a JSON-formatted string into an actual JSON object that other nodes can consume. In ComfyUI, JSON strings show up everywhere - an LLM node's structured output, a settings payload read from a file, config text pasted into a workflow - and most of the time you can't feed that string to a node that wants real data. This node is the bridge.
The context that makes it matter: structured prompting is increasingly how people get LLMs to return usable data (the KB's prompt-engineering material covers how JSON as a response format gives you clean field separation instead of prose). But ComfyUI nodes that take JSON want an object, not a string - so you land here. The typical chain is: LLM node → returns a JSON string → Text to JSON → a node that reads fields out of the object, or back into a string via the pack's JSON To Text (DP_JSONToText) for display or saving.
How it works
It's json.loads() with a safety net. If the string parses cleanly, you get the object and an empty error_message. If it doesn't, the node tries to fix common mistakes before giving up: it swaps single quotes for double quotes, inserts commas between adjacent }{ objects, and wraps the whole thing in braces or brackets if they're missing. If the repair works, it still tells you - error_message comes back as "JSON was corrected." That's a deliberate signal, so you can distinguish "this was already valid" from "this was sloppy and got patched."
The inputs that matter
Only one: text_input, a multiline string. Paste your JSON, wire a string in, that's it.
Two outputs:
json_output- the parsed object. This is what you wire downstream.error_message- empty on success, otherwise the parser's complaint (or the "corrected" notice).
Installation
Standard pack install - ComfyUI Manager, searching "DebugPadawan's ComfyUI Essentials", or:
cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
Restart ComfyUI. Pure json module, no models, no extra dependencies.
Gotchas
The error behavior is the thing to internalize. On genuinely invalid JSON, json_output comes back None and the failure lands in error_message - it doesn't raise. So if a workflow downstream seems dead, check whether you're feeding a None into a node that expects an object. The auto-fix is clever but has limits: it handles quote/brace problems, not trailing commas or nested syntax errors, and its single-quote swap can misfire if a string legitimately contains an apostrophe. Also note that "JSON was corrected." is not an error - read the message before assuming the node failed. And the fix wrapping logic assumes objects, so a top-level array with only one element can come back wrong. Test with the node's default {"key": "value"} first and you'll see the happy path in two seconds.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text_input | STRING | {"key": "value"} | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| json_output | JSON | — |
| error_message | STRING | — |