LLM JSON Repair
Paste broken or truncated LLM JSON and get clean, valid JSON back. Fixes code fences, trailing commas, single quotes and missing brackets — in-browser.
LLM JSON Repair
How to Use the LLM JSON Repair Tool
Paste the broken JSON
Drop in whatever your model returned — even if it is wrapped in ```json fences, has explanatory prose around it, or was cut off mid-sentence. Paste it exactly as you received it.
Watch it repair live
The tool runs on every keystroke. It strips fences and prose, converts single quotes to double, quotes bare keys, drops trailing commas, and closes any unterminated strings or missing brackets from truncated output.
Read the status line
A green "Valid JSON ✓" means it parsed cleanly. If repairs were applied, the status lists exactly what was fixed. If the input is too damaged, it shows a best-effort result and tells you it could not fully repair.
Copy the clean result
Hit Copy to grab the pretty-printed, two-space-indented JSON. Everything happens in your browser — nothing you paste is ever uploaded, logged, or sent to any AI.
Why LLMs Keep Emitting Broken JSON
Large language models are trained to predict the next token, not to satisfy a grammar. When you ask one for JSON, it produces something that looks like JSON because it has seen millions of JSON examples — but nothing in its decoding loop guarantees the result is well-formed. That gap is why developers building on top of ChatGPT, Claude, Gemini, and open-weight models all run into the same recurring failures. A single malformed character is enough to make JSON.parse throw, and a thrown parser at the wrong moment can take down a whole pipeline.
The most common failure is the markdown code fence. Chat-tuned models love to wrap answers in ```json … ``` blocks because that is how code is presented in their training data. The fence is helpful for a human reader and fatal for a parser — the backticks are not valid JSON. Closely related is surrounding prose: "Sure, here's the JSON you asked for:" before the object and "Let me know if you need anything else!" after it. Both have to be stripped before the payload can be parsed, which is exactly what this tool does by isolating the text between the first opening bracket and the last closing one.
The second family of problems comes from the model borrowing habits from other languages. It will write single-quoted strings and unquoted object keys because Python, JavaScript object literals, and YAML all allow them — but strict JSON requires double quotes around every string and every key. It will leave a trailing comma after the last element of an array or object, again because most programming languages tolerate it. None of these are bugs in the model so much as bleed-through from the broader corpus it learned from, and all of them are mechanical, reversible mistakes.
"An LLM does not 'know' JSON is a strict grammar. It produces text that resembles the JSON it has seen — and resemblance is not validity."
Truncation is the failure you cannot retry your way out of
The hardest case is truncation. Every model has a maximum output length, and when a response hits that ceiling it simply stops — often in the middle of a string value, leaving an unterminated quote and a stack of brackets that were never closed. You see this constantly with long arrays of objects: the model gets ninety percent of the way through a list and the generation budget runs out. The raw text is unrecoverable by a strict parser, but it is very recoverable by a tolerant one: walk the text while tracking whether you are inside a string, close the dangling string, then pop a bracket stack to append the missing ] and } characters in the right order. That is precisely the strategy this repairer uses, and it is why it can salvage output that a naive "find and replace" approach would mangle.
Why a string-aware repair matters
The reason careless JSON fixers corrupt data is that they treat the text as a flat string and blindly replace characters — turning every single quote into a double quote, including the apostrophe inside "it's", or deleting a comma that legitimately lives inside a string value like "Smith, John". A correct repair has to track in-string state: it must know whether the comma, brace, or quote it is looking at is structural punctuation or ordinary text inside a value. This tool reads the input character by character, honours backslash escapes, and only rewrites punctuation that sits outside a string. That distinction is the whole difference between a tool you can trust with real model output and one that quietly damages your data. For deeper structural problems the right long-term fix is constrained decoding or a JSON-schema mode on the model itself — but when you just need to rescue the response sitting in front of you, a tolerant, string-aware repair gets you a clean object you can parse and move on.
10 Facts About LLM JSON Output
Models predict tokens, not grammar — nothing in plain decoding guarantees the JSON is well-formed.
The markdown code fence (```json) is the single most common reason a model's JSON fails to parse.
Chat models add prose like "Here's the JSON:" — friendly for humans, fatal for JSON.parse.
Single quotes bleed in from Python and JS object literals; strict JSON requires double quotes.
Unquoted keys (name: instead of "name":) are valid JavaScript but invalid JSON.
A trailing comma after the last element is tolerated by most languages but rejected by JSON.
Truncation at the output-length limit leaves unterminated strings and unclosed brackets.
Naive fixers corrupt data — they mangle the apostrophe in "it's" or a comma inside a value.
A correct repair is string-state aware: it only rewrites punctuation outside of string values.
The durable fix is constrained decoding or schema mode — but a tolerant repair rescues what you already have.
Frequently Asked Questions
- It strips markdown code fences and any prose around the JSON, converts single-quoted strings and keys to double quotes, quotes bare object keys, removes trailing commas, and closes unterminated strings and missing brackets caused by truncated output. Then it re-parses and pretty-prints the result.
- No. The entire repair runs in your browser with plain JavaScript. Nothing you paste is uploaded, logged, stored, or sent to any model or third party. You can use it on sensitive payloads safely.
- Chat-tuned models learned to present code inside markdown fences because that is how code appears in their training data. The fence is helpful to read but is not valid JSON. This tool removes it automatically, so you can leave it in when you paste.
- Often, yes. When a model hits its output-length limit it stops mid-value, leaving an open string and unclosed brackets. The tool tracks the bracket stack, closes the dangling string, and appends the missing closing brackets in the correct order to produce a parseable object.
- No. The repair is string-state aware: it reads the input character by character and only rewrites structural punctuation that sits outside of a string. A comma in "Smith, John" or a brace inside a value is left untouched, and backslash escapes are preserved.
- It means the input was damaged beyond what mechanical repair can safely reconstruct — for example, deeply scrambled structure or missing required values. The tool still shows its best-effort result so you can finish the fix by hand, rather than silently guessing.
- Yes. The failure modes — fences, prose, single quotes, bare keys, trailing commas, truncation — are common across ChatGPT, Claude, Gemini, and open-weight models, because they stem from how all of them generate text. The repair is model-agnostic.
- Use the model's structured-output or JSON-schema mode if it has one, raise the max-output-token limit to avoid truncation, and instruct the model to return only JSON with no fences or commentary. This tool is for rescuing the responses you already have when those guards are not in place.
- When the status reads "Valid JSON ✓" or "Repaired ✓", the result was produced by parsing the repaired text with the browser's native JSON parser and re-serialising it, so it is guaranteed to be standards-compliant JSON ready to use anywhere.
- Completely free, with no account, sign-up, or usage limit. It runs entirely in your browser and collects no data.
Related News
You may be interested in these recent stories from our newsroom.
No related news yet for this tool. Our editorial team publishes new pieces every week.
Browse all news →75 more free tools
Calculators, converters, security tools — no signup.