How to use the fix llm json
- Paste the full model reply, including any text before or after the JSON.
- The tool finds the first complete JSON object or array, removing ```json fences and prose.
- Review the repairs, such as closed brackets, straightened quotes or removed trailing commas.
- Apply and copy clean JSON with Ctrl/Cmd+Alt+C for your code or pipeline.
Features
- Extract from prose: Finds the JSON inside "Sure! Here's the data:" style replies.
- Strip fences: Removes ```json, ``` and stray backticks.
- Complete truncated output: Closes open strings, arrays and objects when a reply was cut off; the last value is flagged.
- Smart quotes: Converts curly “quotes” that chat interfaces insert into straight double quotes.
Example
Truncated model reply → JSON
Input
Sure! Here is the data:
```json
{"city": “Paris”, "tags": ["food", "art",], "notes": "Open late on ThuOutput
{"city": "Paris", "tags": ["food", "art"], "notes": "Open late on Thu"}Prose and fence removed, curly quotes straightened, trailing comma dropped, the open string and object closed. "notes" is flagged because the model may have meant more.
Typical LLM JSON failures
| Error | Cause | Fix |
|---|---|---|
| Unexpected token S | Reply starts with prose like "Sure!". | Text outside the JSON is dropped. |
| Unexpected token ` | Markdown code fence. | Fences removed. |
| Unexpected token “ | Curly quotes from a chat UI or word processor. | Replaced with straight quotes. |
| Unexpected end of JSON input | Output hit the max token limit. | Open structures closed; last partial value flagged. |
| Unexpected non-whitespace after JSON | Model added an explanation after the closing brace. | Trailing text dropped. |
Preventing broken JSON at the source
Most providers now offer structured outputs or a JSON mode that constrains generation to valid JSON, sometimes against a schema you supply. Use it where available, and keep the output token limit comfortably above the size you expect, since truncation is the one failure no mode prevents.
In code, always parse the reply inside a try/catch and validate the shape before using it. This page is for debugging the replies that still slip through, and for one-off copies from a chat window.
Fix LLM JSON FAQ
Why does ChatGPT return invalid JSON?
Models generate text token by token and are not guaranteed to follow JSON grammar unless constrained. Common problems are Markdown fences, extra explanation, trailing commas and replies cut off at the output limit.
How do I get valid JSON from an LLM every time?
Use the provider's structured output or JSON mode with a schema where available, set a high enough output token limit, and validate the result in code.
Can it fix JSON that was cut off mid-reply?
It closes the open brackets so the text parses, but data the model never wrote cannot be recovered. The last, possibly incomplete, value is flagged.
Does it send my prompt or output to an AI?
No. Extraction and repair are rule-based code running in your browser. No model is called.
What if the reply contains two JSON blocks?
The first complete object or array is extracted. Paste the second block on its own to repair it separately.
Does it handle JSON Lines from batch jobs?
Not yet. Paste one object at a time for now; NDJSON support is planned.

