JSON Repair · 5 min read
Fix Broken JSON from ChatGPT, Claude, and LLM Output
Large Language Models are incredibly useful for generating structured data — but the JSON they produce is often broken. Truncated output, Python-style booleans, unescaped quotes, and markdown code fences are just a few of the common issues. This guide covers how to auto-detect and fix these problems using the JSON Repair Tool.
Why LLMs Generate Broken JSON
LLMs generate text by predicting the next token, not by ensuring valid syntax. This leads to five common failure modes:
- Truncated output — the response is cut off mid-object, missing closing brackets and braces.
- Python booleans —
TrueandFalseinstead oftrueandfalse. - Python None —
Noneinstead ofnull. - Markdown code fences — JSON wrapped in
```json ... ```blocks. - Commented or mixed content — explanatory text around the JSON like "Here is the data:" before the JSON.
- Unescaped special characters — quotes inside strings without backslash escaping.
The repair tool handles all of these in a single click — just paste the raw ChatGPT output and let the tool fix it.
1. Fixing Truncated JSON
Truncation is the most common LLM JSON error. The output just stops — missing closing brackets, braces, or even the end of a string. Consider this ChatGPT output:
{
"users": [
{"id": 1, "name": "Alice", "role": "admin},
{"id": 2, "name": "Bob", "role": "user"}
Notice: "admin has a missing closing quote, the array is not closed (] missing), and the object is not closed (} missing). The repair tool detects the open structures and closes them:
{
"users": [
{"id": 1, "name": "Alice", "role": "admin"},
{"id": 2, "name": "Bob", "role": "user"}
]
}
Valid JSON in milliseconds — no manual bracket counting needed.
2. Python Booleans and None Values
LLMs trained on Python-heavy data often output Python-style values:
{
"name": "Widget",
"inStock": True, // Python boolean — should be true
"discount": None, // Python None — should be null
"isPremium": False // Python boolean — should be false
}
The repair tool finds and replaces all Python-style values:
{
"name": "Widget",
"inStock": true,
"discount": null,
"isPremium": false
}
Valid JSON, ready for any JavaScript, Python, or Java parser.
3. Markdown Code Fences and Commentary
LLMs often wrap JSON in ```json code blocks with explanatory text around them. The repair tool strips everything except the JSON content:
Here is the JSON data you requested:
```json
{
"status": "success",
"count": 3,
"items": ["a", "b", "c"]
}
```
Let me know if you need modifications.
The tool extracts only the JSON block, ignoring the surrounding commentary. If there are multiple code fences, it picks the one that contains valid JSON-like content.
Try the Free JSON Repair Tool
Fix broken JSON from ChatGPT, Claude, and any LLM. Truncated, Python booleans, markdown fences — all fixed. No signup, no tracking.
Repair JSON Now →Best Practices for LLM JSON Generation
- Ask for raw JSON only. In your prompt, add "Return only valid JSON, no markdown formatting, no explanations." This reduces but doesn't eliminate errors.
- Always repair before using. Even if the JSON looks correct, run it through the repair tool. Edge cases like trailing commas or unescaped quotes are hard to spot visually.
- Validate the result. After repair, use the JSON Editor to validate and format the output before integrating it into your application.
- Set output length limits. Truncation happens more often with large JSON outputs near the model's token limit. Request smaller chunks if possible.
- Use JSON mode when available. Some APIs (like OpenAI's JSON mode) constrain the model to return valid JSON. Enable it if your API supports it, but still repair as a safety net.
Frequently Asked Questions
Why does ChatGPT generate broken JSON?
LLMs generate text probabilistically, not by following grammar rules. Common causes include: output being truncated mid-structure, using Python-style booleans (True/False instead of true/false), wrapping JSON in markdown code fences, and inserting commentary text around the JSON object.
How do I fix truncated JSON from an LLM?
The JSON repair tool automatically detects truncated JSON and appends missing closing brackets and braces. Paste the incomplete output and the tool will close all open structures. If the truncation is in the middle of a value, the tool adds closing quotes and brackets to make the JSON valid.
Can the tool fix Python-style booleans in JSON?
Yes. Python uses True, False, and None while JSON requires true, false, and null. The repair tool automatically detects and replaces Python-style values with the correct JSON equivalents. The same applies to Python None becoming JSON null.
How does the tool handle markdown code fences around JSON?
LLMs often wrap JSON output in ```json or ``` code fences. The repair tool strips these fences and any surrounding commentary text before attempting to parse the JSON. Only the actual JSON content is preserved and repaired.
Is my LLM output data safe with this repair tool?
100% safe. All repair happens in your browser. Your data never leaves your computer. No server uploads, no storage, no tracking.