Fix Broken JSON
instantly, for free
Paste your invalid JSON and get valid output back. Automatically repairs trailing commas, unquoted keys, single quotes, JavaScript comments, and undefined values.
6 Fix Transforms
Six sequential repairs handle the most common ways JSON breaks — in the right order to avoid conflicts.
Shows What Changed
After repair, the result is validated and formatted so you can see exactly what was fixed.
AI-Output Friendly
Handles the messy JSON that LLMs and APIs produce — JS comments, trailing commas, unquoted keys.
Six transforms applied automatically
] and } — the most common JavaScript-to-JSON mistake.
'value' to "value" throughout strings and keys.
// line and /* block */ comments that are valid in JS5 but not JSON.
undefined values with null — valid JSON's closest equivalent.
Your data never leaves your device
Secure by architecture, not by policy
- No backend server — there is nowhere for your data to go
- No WebSocket, no fetch, no XHR for your JSON content
- All repair transforms run entirely in your browser using pure JavaScript regex
- Useful for sensitive API responses, config files, and tokens
- No account, no login, no cookies tied to you
Related JSON tools
Common questions answered
What types of broken JSON can the repair tool fix?
It fixes trailing commas, unquoted keys, single-quoted strings, JavaScript comments (//, /* */), and undefined values.
Is the JSON repair tool free?
Yes, completely free with no login required.
Does JSON repair send my data online?
No. Repair runs entirely in your browser — your JSON is never uploaded.
What if the repair tool can't fix my JSON?
The tool shows exactly what repairs it applied. If it can't fully repair, it shows the error location so you can fix it manually.
Can I use the repaired JSON in other tabs?
Yes. After repair, click 'Use in Format' to send it directly to the Format tab for pretty-printing.
What is JSON repair?
JSON repair automatically fixes common syntax errors that make a JSON document invalid. Real-world JSON often arrives broken: APIs return malformed responses, copy-paste introduces trailing commas, and hand-edited files accumulate single quotes, unquoted keys, and JavaScript comments. A repair tool applies transformations to produce valid JSON.
This tool applies six repair strategies in sequence: removing JavaScript comments (// and /* */), converting single quotes to double quotes, quoting unquoted keys, removing trailing commas, replacing undefined with null, and fixing unescaped control characters. Each repair is non-destructive — it modifies only the syntax, not the data values.
{
// user data
name: 'Alice',
age: 30,
active: undefined,
}
{
"name": "Alice",
"age": 30,
"active": null
}
Get the most out of this tool
- Use repair when pasting JSON from JavaScript source code — it typically has trailing commas, single quotes, and comments.
- The repair tool chains with the formatter: repair broken JSON first, then format it in one workflow.
- Repair handles the five most common errors: trailing commas, single quotes, unquoted keys, comments, and undefined values.
How automatic JSON repair works
JSON repair, also called JSON recovery or JSON fixing, is the process of transforming syntactically invalid JSON into valid JSON while preserving as much of the original data as possible. It is fundamentally different from validation — a validator only tells you what is wrong, while a repair tool also fixes it. The challenge is that JSON errors are often ambiguous: a missing closing brace could be fixed by adding one at the end, or by removing an extra opening brace somewhere in the middle. The repair algorithm must make a reasonable inference about which fix preserves the author's intent.
The most common repair case is trailing commas. When a developer builds a JSON string by hand or edits a JSON file, they often add a comma after the last element before closing a bracket. Standard JSON forbids this. The repair tool detects this pattern (a comma immediately followed by } or ]) and removes the excess comma, producing valid JSON in milliseconds.
Single-quoted strings are another very common issue. Developers familiar with Python or JavaScript sometimes write JSON-like data using single quotes: {'key': 'value'}. This is invalid JSON but has clear intent. The repair tool replaces single-quoted string delimiters with double quotes, correctly handling cases where the string content itself contains a single quote (which it escapes) or a double quote (which it already escapes).
Unquoted keys appear frequently in data copied from JavaScript console output or configuration files inspired by HJSON. A key like {name: "Alice"} has an unquoted identifier as a key, which is valid JavaScript but not JSON. The repair tool identifies bare identifiers in key position and wraps them in double quotes: {"name": "Alice"}.
JavaScript-style comments (//, /* */) sometimes appear in JSON that was originally JSONC (JSON with Comments) and was copy-pasted into a context expecting standard JSON. The repair tool strips both line comments and block comments before returning clean JSON. Similarly, JavaScript undefined values — which have no JSON equivalent — are converted to null, and NaN and Infinity values are also replaced with null since they are illegal in JSON.
Truncated JSON is a special repair case that arises frequently with large API responses. If a connection is interrupted mid-transmission, you receive a partial JSON document — perhaps a JSON array with only some elements, the final closing bracket missing. The repair tool detects unclosed structures and closes them at the deepest level, preserving the data already received and making the result parseable.
LLM-generated JSON often contains formatting errors because language models do not strictly follow the JSON grammar — they optimize for plausibility, not correctness. Common LLM JSON mistakes include markdown code fence markers (```json), prose before or after the JSON body, and occasional trailing commas or missing quotes on numeric keys. The repair tool handles all of these cases, making it especially useful in AI application pipelines.
When developers use this tool
What the repair tool fixes automatically
- Trailing commas: The trailing comma after the last element in objects and arrays is the most common issue. The repair tool removes these automatically throughout the entire document, not just at the top level.
- Single-quoted strings: Python-style and JavaScript-style single-quoted strings are converted to properly double-quoted JSON strings, with internal single quotes escaped and internal double quotes properly handled.
- JavaScript comments: Line comments (// ...) and block comments (/* ... */) are stripped from the document. This is the most common repair needed for JSON exported from tools that use JSONC internally.
- Undefined and NaN values: JavaScript-specific values with no JSON representation are converted to null, the closest JSON equivalent, to produce valid output that downstream parsers can handle.
- Unclosed structures: Missing closing braces or brackets at the end of truncated JSON are automatically inserted at the correct nesting depth to make the document structurally complete.
Additional frequently asked questions
How does the repair tool decide what to fix when JSON is ambiguous?
The repair algorithm applies a prioritized set of heuristics in order of most-to-least common errors. It first tries minimal changes (removing trailing commas, adding missing quotes) before considering structural changes (closing unclosed brackets). The goal is always to preserve the original data intent with the smallest possible transformation.
Can the repair tool fix JSON with completely wrong structure?
The repair tool handles common formatting problems well, but if the JSON structure is fundamentally different from valid JSON — for example, a CSV or XML file with a .json extension — it cannot produce meaningful output. It repairs damaged JSON, not incorrectly formatted non-JSON data.
Does repairing JSON change any values?
The repair tool only modifies structural elements (commas, quotes, brackets) and illegal value types (undefined → null). It never changes string content, numeric values, or boolean values. Your data is preserved; only the syntax is corrected.
Is the repair tool available as an API?
Yes. The REST API at api.jsonfmt.dev/repair accepts a JSON POST body and returns repaired JSON. This lets you integrate repair into server-side pipelines, preprocessing steps, or automated data ingestion workflows where you cannot run a browser.