Paste JSON that won't parse and get valid JSON back, with a log of every change. Trailing commas, single quotes, comments, code fences, and missing brackets are fixed automatically.
This tool runs entirely in your browser. What you enter is never sent anywhere.Your input is never sent anywhere.
DetailsPaste your broken JSON
Output options
Indent
Key order
Output format
Paste your JSON and click “Repair JSON” (or press Ctrl/Cmd+Enter). The problems found and the fixed result will appear here.
Fix Invalid JSON From AI Chats and Config Files
JSON copied from an AI chatbot often fails in JSON.parse() because of a trailing comma, single quotes, a stray comment, or a leftover ```json fence. Config files that people edit by hand break in the same ways.
A JSON formatter assumes the input is already valid, so a broken file only gets you an error such as “Unexpected token.” This tool repairs the syntax first, then pretty-prints or minifies the result so you can use it right away.
Each fix is listed in a change log, so you can see exactly what was edited before you copy the output.
When JSON.parse() Throws an Error
A chatbot's JSON won't parse
You copied JSON from an AI reply, and your code throws an “Unexpected token” error. Paste it here to find the cause and get a version that parses.
Converting JSON5-style config to strict JSON
Config written with comments, unquoted keys, or trailing commas may work in some editors and relaxed parsers, but strict parsers such as JSON.parse() reject it. Convert it to standard JSON.
Pulling JSON out of a chat reply
If the reply starts with a line like “Here is the JSON:” or wraps the data in a code fence, the tool extracts the part between the first { or [ and the last } or ].
Closing brackets on cut-off output
Responses that hit a length limit often lose the final } or ]. The tool tracks open brackets and appends the missing ones.
How to Fix a JSON Parse Error in 4 Steps
- Paste the broken JSON into the input box, or click Paste from clipboard. Surrounding explanation text or code fences are fine.
- Choose the output options you want: indent size, sorted keys, or minified output.
- Click Repair JSON (or press Ctrl/Cmd+Enter). The tool lists the problems it fixed and shows the repaired JSON with syntax highlighting.
- Copy the result or download it as a .json file. If the repair fails, use the ⟦here⟧ marker to find the spot that needs a manual fix.
Note: Your input and the result stay in your browser's memory and are not sent to a server.
Limits and Checks Before You Use the Output
- Repairs follow common error patterns. The tool can't know what the author intended, so review the result before using it in production.
- Badly damaged JSON, such as keys without values or unrelated text inside the data, can't be fixed automatically.
- The output is re-written by JavaScript: a number like 19.80 becomes 19.8, integers above 9,007,199,254,740,991 lose precision, and if a key appears twice only the last value is kept.
- NaN, Infinity, and undefined have no JSON equivalent, so they are converted to null.
- An apostrophe inside a single-quoted string, as in 'don't', ends the string early. Escape it as \' or switch to double quotes before repairing.
- A bare word used as a value, such as status: ok, is wrapped in quotes and becomes a string.
- Everything runs in your browser. Your JSON isn't uploaded or stored.
Common JSON Syntax Errors and Their Fixes
Typical errors from chatbot replies and hand-edited config files. The results are shown minified here to save space; the tool pretty-prints by default.
| Error | Before | After |
|---|---|---|
| Trailing comma | {"a":1,"b":2,} | {"a":1,"b":2} |
| Single quotes | {'a':'b'} | {"a":"b"} |
| Comment | {"a":1 // note } | {"a":1} |
| Code fence | ```json {"a":1} ``` | {"a":1} |
| Unquoted key | {a:1} | {"a":1} |
| Python literals | {"a":True,"b":None} | {"a":true,"b":null} |
| Curly quotes | {“a”:“b”} | {"a":"b"} |
| Missing comma between lines | [{"a":1} {"a":2}] | [{"a":1},{"a":2}] |
| Missing closing bracket | {"a":{"b":1} | {"a":{"b":1}} |
Why AI Output and Hand-Edited Files Produce Invalid JSON
How the usual syntax errors get in, and how repairing differs from formatting.
Why AI-generated JSON breaks
Language models write text one token at a time, so habits from other formats can leak in: Python-style dictionaries (single quotes, True, False, None), explanatory comments, and Markdown code fences (```json). If a response hits its length limit, the JSON can stop partway and lose its closing brackets.
JSON repair vs. JSON formatting
A formatter or beautifier expects input that JSON.parse() can already read, and only changes indentation and line breaks. A repair tool works on text that doesn't parse: it finds what breaks the syntax and fixes it. For invalid JSON, repair comes first and formatting second.
How trailing commas, single quotes, and comments end up in JSON
A trailing comma appears when you delete the last item in a list and forget the comma before it. Single quotes come from JavaScript and Python habits. Comments are common in relaxed formats such as JSON5 and JSONC, but strict parsers like JSON.parse() reject them, as does standard JSON (RFC 8259).
What can't be fixed automatically
Structurally broken JSON, such as keys that lost their values or unrelated sentences inserted inside a string, can't be fixed by pattern matching. Use the error excerpt the tool shows to find the spot, then fix it by hand.
Common Mistakes When Fixing JSON by Hand
Pasting invalid JSON into a formatter and getting only an error
A formatter expects valid input. With a syntax error it shows a message like “Unexpected token” and nothing else, so you still don't know what to change.
💡 See the solution▼
Copying the chat reply text along with the JSON
If you copy a line like “Here is the JSON:” with the data, the extra text makes the parse fail.
💡 See the solution▼
Deleting one trailing comma and hitting the next error
The error message points at one problem, but the text may also have single quotes, comments, or unquoted keys. Each fix reveals the next error.
💡 See the solution▼
Counting closing brackets by eye
In deeply nested or long JSON, it's easy to lose track of how many } and ] are missing.
💡 See the solution▼
Using the repaired output without checking it
A successful repair means the syntax is valid. It doesn't mean every value is what the author intended.
💡 See the solution▼
Questions About Invalid JSON and Auto-Fix
Q.What's the difference between a JSON repair tool and a JSON formatter?
A. A JSON formatter (or beautifier) adds indentation and line breaks to JSON that is already valid. If the input has a syntax error, it can only show an error message. A repair tool finds the syntax errors, such as trailing commas, single quotes, comments, and leftover code fences, and fixes them so the text parses. This tool repairs first and then pretty-prints or minifies the result.
Q.What kinds of invalid JSON can this fix?
A. It fixes trailing commas, single-quoted strings, // and /* */ comments, Markdown code fences, unquoted keys, Python-style True, False, and None, NaN, Infinity, and undefined (converted to true, false, or null), curly quotes around strings, line breaks inside strings, missing commas between values on separate lines, and missing closing brackets. Every fix is listed in the change log.
Q.What happens if the JSON can't be repaired?
A. The tool shows the parser's error message and a short excerpt of the text around the error, with a ⟦here⟧ marker at the position. Structural damage, such as keys without values or unrelated text inside the data, is not repaired automatically. Use the marker to find the spot and fix it by hand.
Q.Can I paste a chatbot reply that includes explanation text?
A. Yes, in most cases. If the input doesn't start with { or [, the tool takes everything from the first { or [ to the last } or ] and repairs that part. A Markdown code fence around the JSON is removed too. If the text before the JSON contains a { or [, or the text after it contains a } or ], that text is included, so trim it first.
Q.Can it fix JSON that was cut off in the middle?
A. Partly. Missing closing brackets are added, a comma left at the very end is removed, and a string that was cut off is closed at the end of the input, so the last value may be incomplete. If the output stops right after a key or a colon, or partway through a value such as a number, the result may still fail to parse.
Q.Is my JSON uploaded anywhere?
A. No. Detection, repair, and formatting all run in JavaScript in your browser. The tool doesn't upload your text or send it to an external API.
Q.Is the repaired JSON guaranteed to be correct?
A. When the tool shows a success message, the result has passed JSON.parse() in your browser, so the syntax is valid. The content isn't guaranteed to match what the author meant, especially if the original structure was ambiguous. Review the output and the change log before you use it.
Q.Can I sort the keys alphabetically?
A. Yes. Turn on Sorted A–Z in the output options and the keys of every object are sorted, including nested ones. The sort uses JavaScript's default string order, so uppercase letters come before lowercase ones (Zebra comes before apple). Sorting is handy when you want to compare two JSON files in a diff tool.
Your feedback
makes this tool better.
Tell us which features you'd like, what should be fixed, or which new tool you'd like to see. An engineer reads every submission and uses it to guide development.