Skip to content
Salyro
Tool

JSON repair

Fixes the broken JSON models return — code fences, stray text, trailing commas, single quotes, cut-off answers — with every change marked certain or a guess.

What it does

Paste a model's answer as it came back. JSON repair finds the JSON in it, makes it valid, and shows each repair: what it changed, the line and column, and whether the repair is certain or a guess. The result comes with a diff against what you pasted. Everything runs in your browser: nothing you paste is sent anywhere.

Valid JSON is left exactly as it is.

What it repairs

Certain. These have one meaning, so the repair cannot change what the answer says:

  • a Markdown code fence around the JSON, and text before or after it;
  • trailing commas, and commas with nothing before them;
  • // and /* */ comments;
  • single quotes and typographic quotes around strings, and keys without quotes;
  • Python's True, False and None;
  • line breaks and other control characters inside strings;
  • numbers written the way JavaScript allows, such as +1, .5 or 2.;
  • a whole answer that is one broken value, such as True or 'text'.

Guesses. These read the text one way when another is possible, so check them:

  • An answer cut off at the end, for example at max_tokens. The open strings, lists and objects are closed, but whatever was left unwritten is not there.
  • A missing comma or colon between members.
  • A double quote inside a string that was not escaped. It is read as part of the string when what follows does not end a value.
  • A value without quotes, such as a date, read as a string.
  • NaN, Infinity and undefined, written as null.
  • A number with a leading zero, such as 02134, read as a number. It may have been meant as text.
  • A quote inside a single-quoted string, read as part of it.
  • More than one JSON value in the text, such as a second object or a bracketed link in the prose. The one that needs no guess is kept, the largest first; if every one needs a guess, the largest is kept. The rest is dropped.

How it works

The repair reads the text once and copies it through, changing only what is not JSON. Your whitespace, key order and numbers are kept as they were, so the diff shows the repairs and nothing else. Re-indent the result shows the same JSON indented instead. Every string and number is kept exactly as written.

What it does not know

  • What the model meant to write after a cut-off. A closed object is valid, but it may be missing fields. Ask for more output tokens rather than trusting a truncated answer.
  • Whether the result matches your schema. Valid JSON can still be the wrong shape. Check the schema itself with the JSON Schema compatibility checker.
  • What cannot be repaired safely. A character that fits nowhere in JSON is reported with its line and column, not guessed around.

FAQ

Why did my model return JSON inside a code fence?

Models trained on Markdown often wrap code in fences, even when asked for JSON only. The fence is removed with certainty. To avoid it at the source, use your provider's structured output feature, which constrains the answer to JSON.

Is a repaired truncated answer safe to use?

Only as far as it goes. The repair closes what was open, so the JSON parses, but anything the model had not written yet is missing. Treat the result as partial.

Sources

The repairs follow the JSON grammar (RFC 8259). No provider data is used: the tool works only on what you paste.

Where the numbers come from

This tool works only on what you enter. It uses no external data and runs entirely in your browser.