JSON Repair Tool
Automatically fix common JSON issues. Perfect for cleaning up LLM outputs, copy-pasted code, or hand-edited configuration files.
Common Issues We Fix
{"a": 1,}→{"a": 1}{'a': 1}→{"a": 1}{a: 1}→{"a": 1}{"a": 1 "b": 2}→{"a": 1, "b": 2}{"a": 1} // note→{"a": 1}{"a": [1, 2→{"a": [1, 2]}What is JSON Repair?
JSON Repair automatically fixes common syntax errors that make JSON invalid. Unlike a validator that just tells you something is wrong, this tool actually fixes the problems and gives you working JSON.
This is especially useful when working with:
- LLM/AI outputs — ChatGPT, Claude, and other models sometimes return malformed JSON
- Copy-pasted code — JSON copied from JavaScript often has trailing commas or single quotes
- Hand-edited configs — Easy to forget a comma or add an extra one
- API responses — Truncated or corrupted responses from network issues
Issues We Automatically Fix
Trailing Commas
JavaScript allows trailing commas, but JSON doesn't. We remove them automatically:
// Before (invalid)
{
"name": "John",
"age": 30, ← trailing comma
}
// After (valid)
{
"name": "John",
"age": 30
}Single Quotes
JSON requires double quotes. We convert single quotes to double:
// Before (invalid)
{'name': 'John'}
// After (valid)
{"name": "John"}Unquoted Keys
JavaScript object keys can be unquoted, but JSON requires quotes:
// Before (invalid)
{name: "John", age: 30}
// After (valid)
{"name": "John", "age": 30}Comments
JSON doesn't support comments, but many config files include them. We strip them out:
// Before (invalid)
{
"debug": true, // enable debug mode
/* timeout in ms */
"timeout": 5000
}
// After (valid)
{
"debug": true,
"timeout": 5000
}Markdown Code Blocks
LLMs often wrap JSON in markdown code blocks. We extract the JSON:
// Before (invalid)
```json
{"name": "John"}
```
// After (valid)
{"name": "John"}Truncated JSON
When JSON is cut off mid-stream (common with LLM outputs), we add missing brackets:
// Before (truncated)
{"users": [{"name": "John"}, {"name": "Jane"
// After (completed)
{"users": [{"name": "John"}, {"name": "Jane"}]}Missing Commas
We detect and add missing commas between elements:
// Before (invalid)
{"a": 1 "b": 2 "c": 3}
// After (valid)
{"a": 1, "b": 2, "c": 3}Working with LLM Outputs
Large Language Models like ChatGPT, Claude, and GPT-4 are incredibly useful for generating structured data, but they sometimes produce invalid JSON. Common issues include:
- Wrapping JSON in markdown code blocks (
```json ... ```) - Adding explanatory text before or after the JSON
- Truncating output mid-object due to token limits
- Using JavaScript-style syntax instead of strict JSON
This repair tool handles all of these cases, making it perfect for AI/LLM workflows.
Programmatic JSON Repair
Need to repair JSON in code? Here are some approaches:
JavaScript/TypeScript
// Using the jsonrepair library (what this tool uses)
import { jsonrepair } from 'jsonrepair';
const broken = "{'name': 'John', 'age': 30,}";
const fixed = jsonrepair(broken);
console.log(fixed); // {"name": "John", "age": 30}
// Parse the repaired JSON
const data = JSON.parse(fixed);Python
# Using json-repair library
from json_repair import repair_json
broken = "{'name': 'John', 'age': 30,}"
fixed = repair_json(broken)
print(fixed) # {"name": "John", "age": 30}When NOT to Use Repair
JSON repair is great for quick fixes, but be careful:
- Don't use for security-critical data — The repair might change the meaning of the data in unexpected ways
- Always validate the result — Make sure the repaired JSON has the structure you expect
- Fix the source — If you're repeatedly repairing JSON from the same source, fix the source instead
JSON5 Alternative
If you're writing configuration files and want a more lenient syntax, consider using JSON5. It's a superset of JSON that allows:
- Comments (single and multi-line)
- Trailing commas
- Unquoted keys
- Single quotes
- Multi-line strings
We also have a JSON5 to JSON converter if you need to convert JSON5 to standard JSON.
Related Tools
- JSON Validator — Validate JSON and see detailed error messages
- JSON Pretty Print — Format repaired JSON nicely
- JSON Minify — Compress JSON after repair
- JSON Escape — Escape special characters in strings
Frequently Asked Questions
Can this fix any broken JSON?
Not always. The tool can fix common syntax issues, but if the data structure itself is corrupted (wrong values, missing fields), it can't know what the correct data should be. It fixes syntax, not semantics.
Is the repaired JSON guaranteed to be correct?
The repaired JSON will be valid JSON (parseable), but you should always verify that the data structure matches what you expect. The repair process makes its best guess about what you intended.
Why do LLMs produce broken JSON?
LLMs are trained on text that includes both valid JSON and JavaScript object literals. They sometimes mix the two syntaxes. Additionally, token limits can cause truncation, and the model might add explanatory text around the JSON.
Can I use this in production?
For quick fixes and development, absolutely. For production systems, consider using the jsonrepair npm package directly with proper error handling and validation.
Common Mistakes & Pro Tips
- Repair is heuristic — always re-validate — The repairer guesses your intent using pattern rules, and on ambiguous input it can guess wrong. After repairing, run the output back through a validator and eyeball the result to confirm the structure matches what you expected.
- Strip markdown code fences from LLM output — ChatGPT and Claude often wrap JSON in ```json ... ``` fences and add a sentence of explanation before or after. The repairer removes the fences and surrounding prose, but if multiple JSON blocks are present it will typically keep only the first or largest — paste one object at a time when in doubt.
- Single quotes and unquoted keys aren't valid JSON — JSON requires double quotes around every key and every string value; {name: 'Bob'} is JavaScript/Python object syntax, not JSON. The repairer rewrites single quotes to double quotes and quotes bare keys, but watch for apostrophes inside values (e.g. it's) which can confuse naive quote conversion.
- Python literals get translated — None, True, and False (capitalized) come from Python dict output and are invalid in JSON. The repairer converts them to null, true, and false; NaN and Infinity have no JSON equivalent and are usually turned into null, which may not be what you want for numeric data.
- Missing brackets are inferred, not guaranteed — If a closing } or ] is missing, the tool appends what it thinks is needed based on the open structures. With deeply nested or truncated data (e.g. a response cut off mid-stream) the inferred closing may attach at the wrong level, so verify nesting after repair.
Frequently Asked Questions
How do I fix the JSON ChatGPT gave me that won't parse?
Paste the entire response, including any ```json fences and explanatory text, into the repairer. It strips the markdown fences and surrounding prose, then fixes common breakages like trailing commas, single quotes, and unquoted keys. Re-validate the result before using it, since the fixes are based on heuristics.
What's the difference between repairing and validating JSON?
Validating only tells you whether the JSON is well-formed and, if not, where the first error is. Repairing actively rewrites the input to make it parse — fixing trailing commas, quote styles, missing brackets, and language-specific literals. Use validation to confirm the repaired output is correct.
Will the repair tool ever change my data's meaning?
It can. Repairs are best-effort guesses, so an ambiguous case like a missing comma between two strings, an unterminated string, or NaN being converted to null can alter values. Always compare the repaired output against your expectation, especially for numbers and truncated input.
Can it fix JSON that was cut off mid-response?
Partially. If a stream was truncated, the tool can close dangling brackets and quotes to make the fragment parse, but it cannot recover content that was never sent. You'll get valid JSON representing only the portion you pasted, so missing fields stay missing.
Does it handle trailing commas and comments?
Yes. Trailing commas before a closing } or ] are removed, since standard JSON forbids them. JSON5/JSONC-style // and /* */ comments are also stripped, because comments are not part of the JSON spec and will break a standard parser.
Is my data uploaded anywhere when I repair it?
No. The repair runs entirely in your browser using JavaScript, and nothing is sent to a server. You can confirm this by opening your browser's network tab — you'll see no outbound request when you paste and repair, which makes the tool safe for sensitive payloads.