How to Fix Invalid JSON
An “Unexpected token” message rarely tells you what is actually wrong. This guide explains the JSON rules that matter, how to find the exact spot of an error and how to fix the mistakes that cause most invalid JSON.
The rules that trip people up
- Strings and keys use double quotes only: "name", never 'name'.
- Every key is a string in quotes. {name: 1} is valid JavaScript but not JSON.
- No comma after the last item in an object or array.
- No comments of any kind.
- Only true, false and null as literal values, always in lower case.
- Numbers have no leading zeros, no plus sign and no hexadecimal form. NaN and Infinity are not allowed.
Find the exact position of the error
Parsers report the position where they gave up, which is usually just after the real mistake. If the error points to a closing brace, look at the line above it: a trailing comma or a missing quote is the typical cause.
Our formatter shows the line and column, quotes the line with a marker under the problem and has a Show in input button that selects the exact character, which is especially useful on a phone.
Errors that come from copying
JSON copied from a word processor, chat app or email often contains curly quotes (“ ”) instead of straight quotes ("), or invisible non-breaking spaces. Both look correct but are invalid. Repair JSON replaces them.
Data copied from Python output uses True, False and None, and single quotes. Data copied from JavaScript code may contain unquoted keys and comments. Repair JSON converts all of these to standard JSON.
When the JSON is cut off
If a log line or terminal output was truncated, the error says the JSON ends too early. No tool can safely guess the missing part. Copy the full response again, or save it to a file and open the file instead.
Check your fix
After editing, the status line turns green and shows how many keys and nesting levels the document has. Switch to Tree view to confirm the structure is what you expect before you use the JSON in your code or configuration.