LLM JSON Repair

Share:

Paste broken or truncated LLM JSON and get clean, valid JSON back. Fixes code fences, trailing commas, single quotes and missing brackets — in-browser.

RT-AI-031 · AI Tools
Your browser is too old for this tool’s interactive features. Please update to Safari 13.1, Chrome or Edge 80, Firefox 74 or newer.

LLM JSON Repair

Repaired JSON

    Advertisement
    After tool · AD-W1Responsive · Post-tool

    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.

    Read the list of changes

    Every change is listed with its line and column, so you can see what was done to your data. Anything that altered a value, such as NaN becoming null or a string cut off by truncation, is marked as a warning.

    Fix what it refuses

    If the input needs a guess — an unquoted text value, a missing colon — the tool stops and points at the line and column instead of inventing an answer. Fix that spot by hand and it carries on.

    Copy the result

    Choose two-space indentation or minified output and copy it. Everything happens in your browser — nothing you paste is uploaded, logged, or sent to any AI.

    Advertisement
    After how-to · AD-W2Responsive

    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 a great deal of JSON, but nothing in plain decoding guarantees the result is well-formed. That gap is why developers building on hosted chat models and open-weight models alike 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.

    A frequent failure is the markdown code fence. Chat-tuned models wrap answers in ```json … ``` blocks because that is how code is presented to a human reader, and 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. This tool takes the content of the fence when there is one, then looks for the first bracket that can actually open JSON, so a stray "[as requested]" in the prose is not mistaken for the data.

    The second family of problems comes from the model borrowing habits from other languages. It writes single-quoted strings the way Python prints a dictionary, unquoted keys the way JavaScript and YAML allow, comments, Python's True and None, and trailing commas that many languages accept. Strict JSON, as RFC 8259 defines it, allows none of these: every string and every key takes double quotes, and values are separated by single commas with nothing after the last one.

    "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. Long arrays of objects are where this bites. A tolerant parser can recover what arrived: it tracks whether it is inside a string, closes the dangling string, drops a key whose value never arrived, and appends the missing ] and } in the right order. Be clear about what that gives you: the last string keeps only the part that arrived, and anything after the cut is gone. The tool marks a cut-off string as a warning for exactly that reason.

    Why a string-aware repair matters

    Careless JSON fixers corrupt data because they treat the text as a flat string — turning every single quote into a double quote, including the apostrophe inside "it's", or deleting a comma that lives inside a value like "Smith, John". A correct repair has to know whether the comma, brace or quote it is looking at is punctuation or text inside a value. This tool reads the input character by character, honours backslash escapes, and only rewrites punctuation that sits outside a string. For deeper problems the durable fix is a structured-output or JSON-schema mode on the model itself; this is for rescuing the response already in front of you.

    What it will not do

    It never changes valid JSON. If what you paste already parses, only its whitespace changes: numbers and strings are carried as the text you wrote, so a 20-digit id is not rounded the way JSON.parse followed by JSON.stringify would round it, and duplicate keys are kept and flagged rather than silently collapsed to the last one. It will not guess. An unquoted text value such as {"a": hello world}, a hex number, a missing colon or a key that is neither quoted nor a plain identifier stops the repair with the line and column, because any fix would be an invention. It tells you when it changed a value. NaN, Infinity and undefined have no JSON form and become null; a number written with leading zeros is read as decimal; a cut-off string keeps only its first part. Each of those is listed as a warning, never applied quietly.

    What RFC 8259 says the repair must respect

    01

    RFC 8259 says object names SHOULD be unique; when they are not, receiving software behaves unpredictably, and many implementations keep only the last pair.

    02

    Numeric values the grammar cannot represent, such as Infinity and NaN, are not permitted in JSON at all.

    03

    Only integers between −(253)+1 and 253−1 are guaranteed to be read back exactly; larger ones are valid JSON but get rounded by JavaScript.

    04

    Inside a string the quotation mark, the backslash and the control characters U+0000 to U+001F must be escaped, which is why a raw line break breaks parsing.

    Frequently Asked Questions

    • Code fences and prose around the JSON, a byte-order mark, // and /* */ comments, single-quoted and curly-quoted strings, bare keys, trailing, doubled and missing commas, raw line breaks and tabs inside strings, invalid escapes, Python's True, False and None, numbers written as +1, .5 or 5., a closing bracket of the wrong kind, and truncation: an open string, a key with no value and unclosed brackets. Each change is listed with its line and column.
    • Only its whitespace. Numbers and strings are kept exactly as written, so large integers are not rounded and escapes are not rewritten, and duplicate keys are kept and flagged. Choosing "Minified" removes the whitespace; "2-space indent" re-indents it.
    • It recovers everything that arrived. It closes the dangling string, drops a key whose value never arrived, and closes the open brackets in the right order. The last string will hold only its first part, and is flagged so you know. Whatever the model never wrote cannot be recovered; raise the output limit and ask again if you need it.
    • Anything it would have to guess at: an unquoted text value such as {"a": hello world}, hex numbers, a missing colon, a key that is neither quoted nor a plain identifier, and nesting deeper than 1,000 levels. It stops with the line and column so you can fix that spot by hand.
    • RFC 8259 does not permit NaN or Infinity, so there is no JSON value that means the same thing. Null is what JavaScript's own JSON.stringify writes for them. The tool lists each replacement as a warning, because it is a change of value, not of punctuation; if a missing score must stay distinguishable from a zero or a blank, handle it in your code.
    • No. The repair reads the input character by character and only rewrites punctuation outside strings. A comma in "Smith, John", a brace inside a value or a // inside a URL is left untouched, and backslash escapes are preserved.
    • No. The entire repair runs in your browser. Nothing you paste is uploaded, logged, stored, or sent to any model or third party, which matters when the payload holds customer data.
    • Use the model's structured-output or JSON-schema mode if it has one, raise the output-token limit to avoid truncation, and ask for JSON only, with no fences or commentary. This tool is for rescuing the responses you already have when those guards are not in place.

    Method & sources

    How it computes

    A string-aware tolerant parser targeting RFC 8259. Valid input keeps its number and string text (only whitespace changes); broken input is repaired step by step, each change reported with line and column; value changes (NaN to null, a cut-off string) are warnings; anything needing a guess (an unquoted text value, a missing colon) is refused with its position. The result is re-checked with JSON.parse (JsonRepairKernel).

    What this tool implements

    • Target grammar is RFC 8259. NaN and Infinity are not permitted (§6), so they become null with a warning; control characters U+0000 to U+001F must be escaped inside strings (§7), so a raw line break or tab is escaped; names SHOULD be unique (§4), so duplicates are kept and flagged rather than collapsed.
    • The JSON is found inside a code fence when there is one, then at the first bracket that can open JSON; prose brackets such as "[as requested]" are skipped, and a broken object is reported as broken rather than swapped for one of its inner fragments.
    • Truncation: an open string is closed and flagged as incomplete, a key whose value never arrived is dropped and listed, and open brackets are closed innermost first.
    • Corrected 2026-11-03: big integers rounded and duplicate keys collapsed on valid input; a truncated trailing object dropped silently while reporting "Repaired"; no handling of comments, NaN, Python True/False/None, raw line breaks, keys cut after a colon, missing commas, prose brackets or wrong closers; the unsourced claim that the markdown fence is "the single most common reason" JSON fails to parse removed.

    Sources

    What can make this go out of date

    • None at runtime: the repair runs in the browser and nothing pasted is sent anywhere.
    Advertisement
    Pre-footer · AD-W3 728 × 90