Utilities
JSON repair: fix broken JSON from LLMs
Paste broken JSON, or a whole model reply, and get valid JSON back, with every change shown. Trailing commas, quotes, comments, code fences and cut-off output are all handled in your browser.
Repaired in your browser. Nothing you paste is sent anywhere.
Paste JSON to check and repair it.
Steps
How to use the JSON repair
- Paste the broken JSON or the model’s whole reply into the box.
- Read the status: already valid, repaired, or the exact spot that needs a manual fix.
- Check any warnings, especially about cut-off output, and look over “What changed”.
- Choose a format, then copy or download the JSON.
Method
How it works
JSON has strict rules: double-quoted keys and strings, no trailing commas, no comments, and true, false and null in lower case. Language models break these rules often, because they learned from code and chat where the looser versions are normal. A single stray comma makes JSON.parse reject the whole response.
How the repair works
First, if the JSON is wrapped in a Markdown code block or surrounded by sentences, the tool takes out just the JSON. Then the open-source jsonrepair library fixes the syntax: it adds missing quotes, turns single quotes into double quotes, removes trailing commas and comments, converts Python’s True, False and None, and closes brackets left open. The result is checked with your browser’s own JSON.parse before it’s shown.
Nothing changes silently
Every edit appears in the “What changed” view, removed text struck through and added text highlighted. The tool also tells you when a repair needs a second look: when output was cut off and the end was closed for you, when several values were merged into an array, or when plain text was turned into a string because there was no JSON in it.
When it can’t help
A repair can make text parse, but it can’t restore data that was never written or decide what an ambiguous structure meant. If the repair fails, the tool points to the line and column so you can fix that spot by hand; the rest is repaired automatically. For production code, prefer your API’s structured output mode and validate every response.
Examples
Worked examples
| Problem | Model output | Repaired |
|---|---|---|
| Trailing commas | {"tags": ["a", "b",],} | {"tags":["a","b"]} |
| Single quotes | {'name': 'Ada'} | {"name":"Ada"} |
| Unquoted keys | {name: "Ada", age: 36} | {"name":"Ada","age":36} |
| Comments | {"retries": 3 // per request } | {"retries":3} |
| Python values | {'ok': True, 'error': None} | {"ok":true,"error":null} |
| Code fence and chat text | Here you go: ```json {"id": 7} ``` | {"id":7} |
| Cut-off output | {"items": [{"id": 1}, {"id": 2 | {"items":[{"id":1},{"id":2}]} |
FAQ
Frequently asked questions
Why do language models produce invalid JSON?
A model writes JSON one token at a time, and much of what it learned from is JavaScript and Python, where single quotes, trailing commas, comments and unquoted keys are normal. Chat models also like to wrap JSON in a Markdown code block or add a sentence before it. And if the reply hits the max_tokens limit, it stops mid-value, leaving brackets unclosed.
How do I get valid JSON from the API in the first place?
Use the provider’s structured output or JSON mode where it exists: these constrain the model to valid JSON, and the strictest versions match a JSON Schema you supply. Set max_tokens high enough for the full answer, ask for JSON only with no explanation, and still validate the result in your code, because a stopped or filtered response can be incomplete.
What can’t it repair?
It fixes syntax, not meaning. If output was cut off, the missing data is gone: the tool closes the open brackets so the rest parses, and tells you it did. If brackets are badly mismatched in the middle, or a value is ambiguous, it may stop and show you the line and column to fix by hand.
Is my data sent anywhere?
No. The repair runs in your browser with the open-source jsonrepair library, so pasted data, including any personal or confidential fields, stays on your device.
Does it handle JSON Lines (NDJSON)?
Yes: several JSON values one after another are combined into a single array, and the tool tells you it did that so you can decide whether that’s what you want.
What’s the difference between validating and repairing JSON?
Validating only tells you whether text is valid JSON and where the first error is; the “Why it was invalid” tab shows exactly that, from your browser’s own JSON.parse. Repairing changes the text so it becomes valid. The “What changed” tab shows every edit, so nothing is changed without you seeing it.
Related
Related tools
- AI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.
- LLM API Cost CalculatorEstimate per-request, daily and monthly API costs.
- AI Model ComparisonCompare prices, context windows and features across models.
- AI Model Pricing PagesSpecs, real costs and cheaper alternatives for popular models.
- Context Window CheckerSee whether your text fits each model's context window.
- Subscription vs API CalculatorFind out whether a chat plan or the API is cheaper for you.