LLM JSON Repair
Fix fences, trailing commas, unquoted keys and cut-off JSON — and see every repair made.
LLM output
5 lines · 115 charsRepair stages
Repaired JSON
8 fixes · 1 pass(es){
"name": "Ada",
"roles": [
"admin",
"editor"
],
"active": true
}| Fix | Count | First position |
|---|---|---|
| Removed Markdown code fence | 1 | 32 |
| Removed prose around JSON | 2 | 0 |
| Quoted unquoted keys | 3 | 0 |
| Python True -> true | 1 | 49 |
| Removed trailing commas | 1 | 35 |
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
Here you go:
```json
{"a": 1,}
```{"a": 1}Two fixes are recorded: fence/prose removal and trailing-comma removal.
Python-style output
{name: 'Ada', active: True, note: None}{"name": "Ada", "active": true, "note": null}Keys, quotes and literals are repaired in separate recorded stages.
Truncated array
{"items": [1, 2{"items": [1, 2]} plus a truncation warningThe 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
Paste raw LLM output
Include fences and prose if they were part of the response; the stripper removes them.
Choose repair stages
Disable any transformation you do not want, for example single-quote conversion on a payload where quotes are meaningful.
Read the fix report
Check each fix, its count and where it occurred; a truncation warning means the content is incomplete.
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
| Stage | What it changes |
|---|---|
| Fences / prose | Removes ```json wrappers and text outside the first container. |
| Comments | Drops // and /* */ comments outside strings. |
| Smart quotes | Normalizes curly quotes where JSON syntax expects a quote. |
| Single quotes | Converts single-quoted strings to escaped double-quoted strings. |
| Unquoted keys | Quotes bare identifiers followed by a colon. |
| Python literals | True / False / None / NaN become true / false / null. |
| Trailing commas | Removes commas before a closing brace or bracket. |
| Closure | Closes 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
Related tools
Agent Tool Flowchart Builder
Design agentic tool-call DAGs with decision branches and bounded loops. Validates reachability, cycle handling, and emits clean Mermaid flowcharts — fully in your browser.
AI Agent Memory & Buffer Simulator
Compare sliding window, summary buffer, and vector memory strategies
AI API Client SDK Generator
Generate typed API client SDK files from OpenAPI specifications or cURL requests
AI Code Explainer
Explain code snippets with grounded cloud AI
AI Code Security Auditor
Scan source code for high-confidence OWASP Top 10 vulnerabilities
AI Code Translator
Translate code into idiomatic implementations in another language