How the JSON repair tool works
Repair (or Ctrl + Enter) runs a fixed sequence of text passes over your input. Each pass tracks where quoted strings begin and end, so text inside a string, such as the // in a URL, is left alone. The order:
- Remove a byte order mark at the start and convert Windows line endings.
- Strip
// line and /* block */ comments.
- Remove commas that sit directly before
} or ].
- Put double quotes around unquoted keys made of letters, digits,
_ and $.
- Turn single-quoted strings into double-quoted ones.
- Replace
NaN, Infinity and undefined with null.
- Insert missing commas in some positions (details below).
- Fix backslash escapes that JSON does not allow.
The result is then checked with JSON.parse. If it parses, the output shows it with your chosen indent and a notification lists the repairs applied. If it still fails, the error box shows the parser message and the repairs tried, and the partly repaired text is left in the output so you can finish by hand. The rules are deterministic: the same input always gives the same output. Validate checks the input as it is.
Example: a JavaScript config pasted as JSON
Settings copied out of a JavaScript file typically have several problems at once:
{
// service settings
name: 'billing-api',
port: 8080,
retries: 3,
timeout: NaN,
tags: ['prod', 'eu-west',],
/* owner */ owner: { team: 'payments', oncall: undefined },
}
Repair reports Removed comments, Removed trailing commas, Added quotes to unquoted keys, Converted single quotes to double quotes, Replaced JavaScript literals and outputs:
{
"name": "billing-api",
"port": 8080,
"retries": 3,
"timeout": null,
"tags": [
"prod",
"eu-west"
],
"owner": {
"team": "payments",
"oncall": null
}
}
What each repair changes in your data
Most repairs only change syntax. These can change values:
- JavaScript literals become
null. "timeout": NaN and "timeout": undefined produce the same output, so the difference between "not a number" and "not set" is lost. -Infinity becomes -null, which still fails: replace it by hand.
- Single-quoted strings are re-quoted safely:
'say "hi"' becomes "say \"hi\"".
- Missing commas are added after a number,
true, false, null, or a closing bracket when another value follows. [1 2 3] becomes [1, 2, 3] and [{"a":1} {"a":2}] gets its separating comma.
- Invalid escapes lose their backslash.
"C:\Users\ada" becomes "C:Usersada". If the value is a Windows path, double the backslashes yourself (C:\\Users\\ada) before repairing.
What it cannot repair
These still need a manual fix:
- A missing comma after a string value, as in
{"name": "Ada" "role": "admin"}. The comma rules do not handle this case correctly, so add the comma yourself.
- Truncated JSON. A response cut off at a size limit is missing its closing brackets, and none are added.
- Extra closing brackets or text after the end of the document.
- Python values
True, False and None. Only the quotes are fixed.
- Unquoted keys with a hyphen or a leading digit, such as
content-type: or 1:. Quote them by hand.
- Raw line breaks or tabs inside a string. Replace them with
\n or \t.
- Hexadecimal numbers (
0x1F), a leading +, or backtick strings.
- Several documents in one input, such as JSON Lines logs, or a JSONP wrapper like
callback({...}). Remove the wrapper or split the lines first.
- Doubled commas such as
[1, 2,,]. Only the last comma is removed.
Valid is not the same as correct
When Repair succeeds, the output is guaranteed to parse, because JSON.stringify produced it. That does not mean it says what the author meant: check for values that became null and strings that lost backslashes. If the broken JSON comes from your own code, fix the code that writes it.
When to use a different tool
- To see the exact parser error without changing anything, use the JSON Validator.
- To make repaired JSON that parses easier to read or smaller, use the JSON Formatter.
- To make manual fixes with bracket matching and highlighting, open the JSON Editor.
Frequently asked questions
Can this tool fix any broken JSON?
No. It applies a fixed set of rules for the most common problems: comments, trailing commas, unquoted keys, single quotes, NaN, Infinity and undefined, some missing commas, and invalid backslash escapes. It does not add missing brackets, remove extra ones, or guess at text that is badly damaged.
Why did NaN, Infinity or undefined become null?
JSON has no way to write those values, and null is the closest valid replacement. JSON.stringify in JavaScript makes the same substitution. If the difference matters to your application, fix the code that produced the data instead of repairing its output.
Why is my JSON still invalid after clicking Repair?
The input has a problem the rules do not cover, such as a truncated file, a missing comma after a string value, or an unquoted key containing a hyphen. The error box shows the parser message and the repairs that were applied, and the partly repaired text is left in the output so you can finish the fix by hand.
Can it fix JSON that was cut off?
No. If a response was truncated by a size limit or a timeout, the closing brackets are missing and the tool does not add them. The data after the cut is gone in any case, so fetch the full response again if you can.
How do I turn Python dictionary output into JSON?
The tool converts the single quotes, but not the Python values True, False and None, so the result still fails. Replace those with true, false and null, or better, print the data with json.dumps() in Python, which writes valid JSON directly.
Is my JSON sent to a server?
No. The repair rules and the final JSON.parse check run in your browser. Pasted text and imported files are not uploaded. Import URL fetches the file directly from your browser.