JSON Repair
Paste broken JSON in the editor above and press Repair. You get valid JSON back and a list of every change, so you can check that nothing was lost. It runs in your browser; nothing is uploaded.
What it fixes
| Input | What it does |
|---|---|
| A ```json code block with text around it | Takes the JSON out and says what text it ignored. |
| Trailing commas and comments | Removes them and counts how many. |
| Python dicts: 'quotes', True, None | Rewrites them as JSON. |
| JavaScript objects: {name: 'Ada'} | Quotes the keys and changes the quotes. |
| Windows paths like C:\Users | Doubles the backslashes so the text stays exactly the same. |
| A raw line break inside a string | Writes it as \n. |
| A missing comma between two values | Adds it. |
| An invisible byte order mark (BOM) | Removes it. |
What it fixes with a warning
These change the meaning a little, so the result is marked with a ! and a note.
| Input | What it does |
|---|---|
| Cut-off JSON | Closes the open strings and brackets. The last value may be incomplete. |
| JSON Lines (one document per line) | Wraps the documents in one array. |
| NaN and Infinity | JSON has no way to write them, so they become strings. |
| undefined | Becomes null. |
What it refuses to repair
Some inputs have no JSON in them. A repair library will still turn them into something that parses, which hides the real bug. This tool stops and tells you what the input is instead.
| Input | What it tells you |
|---|---|
| An HTML page | Shows the page title. The request that returned it needs fixing. |
| [object Object] | The data was lost when the object became a string. |
| An empty input | Usually an empty response body. |
How it works
The repair itself is done by jsonrepair, an open-source library. Before it runs, this page checks for the inputs above that it should refuse, takes JSON out of code blocks, and keeps Windows paths intact (jsonrepair would otherwise drop the backslashes). After it runs, the result is parsed again with JSON.parse to make sure it is valid, and the Changes section under the editor compares it with your input token by token.
Got an error message?
JSON Error Messages, Decoded explains what each parser's message means, with the exact text from Chrome, Firefox, Safari, Node and Python. To check JSON without changing it, use the JSON Validator.