Developer and data

JSON Repair for AI Output

Paste a whole model reply and get the JSON out of it: the code fence stripped, the chatter before and after discarded, and the small syntax errors models make — trailing commas, smart quotes, unquoted keys — repaired, with every change listed.

Repair order: unwrap prose and code fences → normalise smart quotes and dashes → trailing commas, missing commas, unquoted keys, single quotes, Python literals, comments → close unbalanced structures. Every step is reported, and the original text is preserved alongside the repaired output.

Verdict

—

Repaired JSON

Repair log

No repairs yet.

Diff (line by line)

Additions in green, removals struck-through in red. The diff is computed between the unwrapped input and the repaired output as plain text, so the line numbers match the structure of the input.

How to use the JSON Repair tool

Paste a whole model reply on the left. The repair runs in three phases. First, it unwraps the JSON: it strips a leading or trailing markdown code fence, then walks the prose with a string-aware depth counter to find the first (or largest, or every) JSON value. Second, it normalises characters: smart quotes become straight quotes, dashes inside numbers become hyphens, non-breaking spaces become spaces, BOM and zero-width characters are stripped. Third, it applies the safe syntax repairs: trailing commas, missing commas, unquoted keys, single quotes, Python literals, comments, raw newlines in strings, unterminated strings, and unbalanced brackets.

Every step is reported in the Repair Log on the right, with how many times it fired. Nothing happens silently. The Diff panel at the bottom shows additions and removals side by side, with the additions in green and the removals struck through.

What is Aggressive mode?

Aggressive mode also guesses at unquoted barewords (turning name: Alice into "name": "Alice") and replaces NaN, Infinity and undefined with null. The label of the output changes to “repaired with guesses” so it is never confused with a clean parse. Strict mode only strips wrappers and never changes a character, which is the right choice when the model’s output came from a structured prompt and you only want the framing removed.

What happens to truncated replies?

Truncated output is the common case in production. The tool closes unbalanced brackets and braces, marks the result as “completed from a truncated reply”, and lists the keys that were open at the cut. The verdict line says so, so a downstream consumer can reject the result if it cares about completeness.

Why is the unwrap step string-aware?

A naive first-brace match would cut a JSON value off at the first closing brace it found inside a string. The unwrap walks the source with a depth counter that toggles on quote characters and treats backslash escapes correctly, so a string like "a } b" does not break the unwrap. This is the heart of the tool, and the part that does the most work to get right.