How to fix broken JSON from ChatGPT and other LLMs
LLMs almost never return clean JSON. Yellorn's Data Doctor strips the markdown fences, prose, and Python-isms that ChatGPT and Claude add, then shows exactly what it changed.
Why JSON from an LLM is almost never valid
Large language models are trained on prose and code, not on a strict JSON grammar, so the JSON they emit is usually almost right — wrapped in a markdown fence, prefixed with a sentence of explanation, sprinkled with Python-style None/True/False, or cut off when the model hits its token limit. A strict JSON.parse rejects all of these even though the structure underneath is sound.
Yellorn's Data Doctor repairs the common LLM failure modes automatically, in your browser, and shows you every change it made. Here are the patterns it sees most often:
| What the LLM produced | Why it breaks | Yellorn's fix |
|---|---|---|
```json … ``` fence | The backticks aren't valid JSON. | Strips the markdown fence. |
| Prose before/after | “Sure! Here's the JSON:” isn't parseable. | Extracts the JSON object/array. |
None / True / False | Python literals, not JSON. | Converts to null / true / false. |
| Single quotes | JSON requires double quotes. | Normalises to double quotes. |
| Trailing / missing commas | Strict parsers reject both. | Removes trailing, inserts missing. |
| Truncated output | Missing closing }/]. | Auto-closes the open brackets. |
Paste the whole reply — Yellorn finds the JSON
You don't have to clean the response by hand first. Paste the model's entire reply, fence and prose included:
Sure! Here's the user record you asked for:
```json
{
'id': 42,
'name': "Ada",
'active': True,
'roles': ['admin', 'editor',], # note the trailing comma
'last_seen': None
}
```
Let me know if you'd like it in another format.Yellorn parses the object inside immediately. Click Smart Format (Cmd/Ctrl + Shift + F) and the buffer is rewritten as clean, valid JSON:
{
"id": 42,
"name": "Ada",
"active": true,
"roles": ["admin", "editor"],
"last_seen": null
}The status bar reads “Auto-fixed: markdown-code-blocks, single-quotes, python-literals, trailing-commas” — so every transformation is auditable. Nothing is reshaped behind your back.
Recovering truncated or double-encoded JSON
Two LLM-specific messes go beyond simple syntax repair:
- Truncated output. When a model stops mid-object at its token limit, Yellorn auto-closes the missing brackets so the recoverable portion parses. The data after the cut genuinely isn't there, but you keep everything up to it.
- JSON stored as a string. Models (and the logs that capture them) often hand you JSON that was escaped into a string —
"{\"id\":42}"— or two documents glued together by bad escapes. Smart Format can unwrap embedded JSON and recover concatenated documents into a single clean object.
Everything runs locally
All parsing and repair happen in your browser — the text you paste is never uploaded to a server. That makes Yellorn safe for cleaning up LLM output that contains internal API responses, access tokens, or customer data. It is the same recovery ladder described in How to fix broken or invalid JSON, focused on the ways AI tools specifically tend to break it.
Frequently asked questions
Why is JSON from ChatGPT not valid?
LLMs are trained on prose and code, so they routinely wrap JSON in ```json markdown fences, add an explanatory sentence before or after the object, use Python-style None/True/False, leave trailing commas, use single quotes, or stop mid-object when they hit a token limit. Each of these makes a strict JSON.parse fail even though the structure is almost correct.
How do I extract just the JSON from an LLM response?
Paste the entire response into Yellorn. The Data Doctor automatically strips the surrounding prose and markdown ```json fences and parses the object inside. Use Smart Format to rewrite the buffer as clean, pretty-printed JSON, then copy it out. Nothing is uploaded — the repair runs in your browser.
Does Yellorn convert Python dicts to JSON?
Yes. Yellorn recognises Python literals an LLM emits — None becomes null, True/False become true/false, single quotes become double quotes, and tuples or set([...]) become arrays. Paste a Python-style dict and Smart Format returns valid JSON.
Can it recover JSON that was cut off or truncated?
Often, yes. The Data Doctor auto-closes a missing } or ] at the end of a truncated payload so the recoverable part parses. If the model stopped mid-value the data genuinely isn't there, but you still get everything up to the cut, plus a status-bar note of the fix.
Is my data sent to a server when I fix it?
No. All parsing and repair happen locally in your browser. Yellorn never uploads the text you paste, so it is safe to clean up JSON that contains internal API responses, tokens, or customer data.
Related
Where to go next
Try a fix in the editor or browse more articles.