JSON errors and how to fix them
Each page covers one problem that stops JSON from parsing, shows it next to the fixed version, and says how to fix it by hand.
- Trailing comma in JSON
JSON doesn't allow a comma after the last item in an object or list. Why parsers reject it, and how to fix it.
- Unexpected end of JSON input
This error means the JSON stops before every string, list and object is closed. Why JSON gets cut off, and how to recover it.
- Missing comma in JSON
A missing comma between two items is one of the most common JSON errors. Why the parser points at the wrong line, and how to fix it.
- Single quotes in JSON
JSON strings and keys need double quotes. Why 'single quotes' fail, and how to convert them, including quotes inside the text.
- Unquoted keys in JSON
In JSON every key is a string in double quotes. Why {name: "Ada"} fails when JavaScript accepts it, and how to fix it.
- Text before or after the JSON
Chat replies and docs often wrap JSON in other text or Markdown code fences. Why that breaks parsing, and how to get just the JSON.
- Missing curly braces in JSON
Keys and values copied out of a bigger object lose the { and } around them. Why JSON.parse fails on them, and how to fix it.
- Missing square brackets in JSON
Several JSON values separated by commas need [ and ] around them to be one list. Why JSON.parse fails without them, and how to fix it.
- Comments in JSON
JSON has no comments, so // and /* */ make a parser fail. Where commented JSON comes from, and how to remove or keep the notes.
- True, False and None in JSON
Python's True, False and None aren't JSON. JSON uses lowercase true, false and null. How to fix it, and how to get real JSON from Python.
- Curly quotes in JSON
Curly “smart quotes” look like JSON quotes but are different characters. Why they break JSON, where they come from, and how to fix them.
- Unterminated string in JSON
A JSON string that never gets its closing double quote. What JSON.parse reports, where to look for the problem, and how to fix it.
- Line break inside a JSON string
JSON strings must not contain raw line breaks. Why "Bad control character in string literal" happens, and how to write \n instead.
- Missing colon in JSON
In a JSON object, every key is followed by a colon and then its value. What happens when the colon is missing, and how to fix it.
- JSON inside JavaScript or Python code
Code like const data = {...} or JSON.stringify({...}) wraps the data, and it often uses JavaScript syntax. How to turn it into JSON.
- JSON inside a curl command
The JSON body of a curl command comes with the -d flag and shell quotes. How to get the JSON out, including '\'' escapes.