DevTools Logo

LLM JSON Repair

LLM JSON Repair

Fix fences, trailing commas, unquoted keys and cut-off JSON — and see every repair made.

Runs in your browser

LLM output

5 lines · 115 chars

Repair stages

Repaired JSON

8 fixes · 1 pass(es)
Removed Markdown code fence ×1 at character 32
Removed prose around JSON ×2 at character 0
Quoted unquoted keys ×3 at character 0
Python True -> true ×1 at character 49
Removed trailing commas ×1 at character 35
{
  "name": "Ada",
  "roles": [
    "admin",
    "editor"
  ],
  "active": true
}
FixCountFirst position
Removed Markdown code fence132
Removed prose around JSON20
Quoted unquoted keys30
Python True -> true149
Removed trailing commas135

Details

Paste raw LLM output and the repairer first tries JSON.parse: already-valid input is only reformatted. Otherwise it runs toggleable, string-aware stages — strip fences and prose, remove comments, normalize smart quotes, convert single-quoted strings, quote unquoted keys, translate Python literals, remove trailing commas, fix invalid escapes and close truncated containers — re-parsing after each pass with an eight-iteration cap. Every applied fix is listed with its count and first character position, and truncation gets an explicit honesty warning because syntax repair cannot restore missing semantics.

More examples

Fenced response with prose

Prose and fences are removed, the trailing comma is dropped, and both fixes appear in the report.

Python-style object

Keys are quoted, single quotes become double quotes, and Python literals translate to JSON booleans/null.

Cut-off array

Open brackets are closed with an amber warning that semantic completeness cannot be guaranteed.

Examples

Fenced reply

Input
Here you go:
```json
{"a": 1,}
```
Output
{"a": 1}

Two fixes are recorded: fence/prose removal and trailing-comma removal.

Python-style output

Input
{name: 'Ada', active: True, note: None}
Output
{"name": "Ada", "active": true, "note": null}

Keys, quotes and literals are repaired in separate recorded stages.

Truncated array

Input
{"items": [1, 2
Output
{"items": [1, 2]} plus a truncation warning

The tool is explicit that repaired syntax does not restore missing data.

About this tool

LLM JSON Repair fixes the small syntactic mistakes chat models make when they emit structured data: Markdown fences, introductory prose, trailing commas, unquoted keys, single quotes, Python literals, comments and cut-off arrays.

The repairer parses first. Valid JSON is never modified beyond the chosen formatting; invalid input goes through toggleable, string-aware stages, with JSON.parse attempted after each pass and an eight-iteration cap.

Every applied fix is listed with a count and its first character position. When the closure stage fires, an amber warning says the output was likely truncated: syntax can be repaired, but missing semantics cannot be invented. All work happens in your browser.

What this tool does not do

  • Semantic correctness is never guaranteed; repairs are syntactic only.
  • JSON5 features such as hex numbers, Infinity and unquoted string values are out of scope.
  • Very large inputs are limited by browser memory.
  • Duplicate keys follow JSON.parse last-wins semantics.
  • Batch mode splits fenced blocks; unfenced multi-document text is treated as one input.

How to use this tool

  1. Paste raw LLM output

    Include fences and prose if they were part of the response; the stripper removes them.

  2. Choose repair stages

    Disable any transformation you do not want, for example single-quote conversion on a payload where quotes are meaningful.

  3. Read the fix report

    Check each fix, its count and where it occurred; a truncation warning means the content is incomplete.

  4. Copy or download

    Use pretty or minified output and save the repaired JSON for downstream code.

Use cases

LLM pipeline cleanup

Recover structured outputs without discarding a response over a trailing comma.

Prompt engineering

See which mistakes a model makes most often via the aggregated fix report.

Data ingestion

Normalize hand-edited or model-generated JSON before passing it to strict parsers.

Repair stages

StageWhat it changes
Fences / proseRemoves ```json wrappers and text outside the first container.
CommentsDrops // and /* */ comments outside strings.
Smart quotesNormalizes curly quotes where JSON syntax expects a quote.
Single quotesConverts single-quoted strings to escaped double-quoted strings.
Unquoted keysQuotes bare identifiers followed by a colon.
Python literalsTrue / False / None / NaN become true / false / null.
Trailing commasRemoves commas before a closing brace or bracket.
ClosureCloses unterminated strings and open containers, with a warning.

Transformations are string-aware: commas and comment markers inside string values are left untouched.

Common mistakes

Mistake:Trusting a repaired truncated object as complete.

Fix:The amber truncation warning means values may be missing; regenerate if completeness matters.

Mistake:Repairing hex numbers or unquoted string values.

Fix:Those are JSON5 features and out of scope; use a JSON5 validator instead.

Mistake:Enabling every stage without reviewing the report.

Fix:Read the fix list: a transformation you did not expect is a signal to tighten the prompt.

Mistake:Assuming duplicate keys are preserved.

Fix:JSON.parse uses last-wins semantics; the tool warns when repair leaves duplicates.

Mistake:Expecting semantic validation.

Fix:This tool fixes syntax only; schema validation is a separate step.

Frequently asked questions

What kinds of JSON damage does this tool handle?

The repair pipeline targets the most common LLM output faults: trailing commas, unquoted keys, single-quoted strings, missing brackets/braces, stray control characters, duplicate keys, double-encoded string literals, and truncation at token boundaries. It does not fix semantic errors like wrong field names or type mismatches — those require schema validation.

How does the transparency report work?

Every repair step that mutates the input emits a finding with the byte range before/after, the rule that triggered it, and whether it was safe (reversible) or heuristic (best-effort). The report is returned alongside the repaired JSON so you can audit or replay the changes. If the tool cannot produce valid JSON, it returns the original input, an empty result, and a report listing the blocking issues.

What is the duplicate-key policy?

When the same key appears multiple times in an object, the last occurrence wins (matching JSON.parse behavior in most engines). The transparency report flags each duplicate with both values so you can verify the choice. If you need first-wins or merge semantics, use the batch mode with a custom reducer.

Does it handle double-encoded strings like "\"{\"a\":1}\""?

Yes. The escape-stage detector recognizes string literals that decode to valid JSON and recursively repairs the inner payload. This is common when an LLM wraps a JSON payload in a string field. The report marks each layer so you can see the nesting depth.

Can I use this on large JSONL/NDJSON files?

The batch mode processes line-delimited JSON streams (up to ~1 MB in the browser) with per-line reports and a summary. Each line is repaired independently, so one bad record does not block the rest. For server-side workloads, stream the input and call the pure `repairJson` function per chunk.

Is my data sent anywhere?

No. All parsing, repair, and reporting run entirely in your browser. Nothing is uploaded, and no telemetry is collected. The tool is a pure client-side utility.

References & standards