Invalid JSON? 10 Common JSON Errors and How to Fix Them
Trailing commas, single quotes, comments, unescaped quotes and more: how to spot each invalid JSON error from its message, and the exact fix. Free checker.
Published · 5 min read
Invalid JSON almost always comes down to a handful of mistakes: a trailing comma, single quotes, a comment, an unescaped quote inside a string, or a missing comma or bracket. Paste your JSON into the free JSON formatter and click Format: it tells you the line and column where reading stopped. The ten errors below show what each one looks like, the message you'll see, and the fix.
Two tools, two kinds of message. The JSON formatter uses your browser's own JSON reader, so its wording differs a little between Chrome, Firefox and Safari; the examples below are Chrome's. The free JSON visualizer uses its own checker and gives the same plain-English hint in every browser, with the faulty line shown and a marker under the problem. If a formatter message puzzles you, paste the same JSON into the visualizer.
1. Trailing comma
{"name": "Priya", "city": "Pune",}
Messages: the visualizer says Remove the comma before }. Chrome says it expected a double-quoted property name.
Fix: delete the comma after the last item in an object or array. JavaScript allows trailing commas; JSON doesn't. This is the most common error in hand-edited config files.
2. Single quotes
{'name': 'Priya'}
Messages: the visualizer says it found a single quote (use double quotes). Chrome says it expected a property name or }.
Fix: JSON strings and keys must use straight double quotes ". Replace every ' around keys and values. Careful with apostrophes inside text: "Priya's" is fine and needs no change.
3. Keys without quotes
{name: "Priya", age: 29}
Messages: Expected a key in double quotes in the visualizer.
Fix: put double quotes around every key: {"name": "Priya", "age": 29}. JavaScript object literals don't need them; JSON does.
4. Comments
{
"port": 8080 // default
}
Messages: the visualizer says Expected , or } but found "/". A comma may be missing. Ignore the comma hint here; the / is the real clue.
Fix: JSON has no comments, neither // nor /* */. Delete them. If you need notes, add a real field like "_comment": "default port", or keep the file in a format that allows comments (some tools accept "JSON with comments", and YAML allows them; see JSON vs YAML).
5. Unescaped quote inside a string
{"quote": "She said "hello" and left"}
Messages: the error points into the middle of the text, at hello, saying a comma or } was expected. The reader thinks the string ended at the second quote.
Fix: escape inner double quotes with a backslash: "She said \"hello\" and left". For long text, paste it into the free string escaper, choose Escape and JSON, and copy the result into your value.
6. Real line breaks or tabs inside a string
{"address": "12 MG Road
Pune"}
Messages: the visualizer says Line breaks and tabs inside text must be written as \n and \t. Chrome reports a bad control character in a string literal.
Fix: write the line break as \n: "12 MG Road\nPune". The string escaper does this for you too.
7. Backslashes in Windows paths
{"path": "C:\Users\asha"}
Messages: "\U" is not a valid escape.
Fix: double each backslash: "C:\\Users\\asha", or use forward slashes, which Windows usually accepts in paths: "C:/Users/asha".
8. Missing comma or bracket
{"a": 1
"b": 2}
Messages: Expected , or } … A comma may be missing, pointing at the start of line 2.
Fix: add the comma at the end of the previous line. Parsers report where they noticed the problem, which is usually just after the real mistake. For a missing ] or }, the message often says The JSON ends too soon; count your opening and closing brackets, or format a smaller section to narrow it down.
9. JavaScript values that aren't JSON
{"total": NaN, "discount": undefined, "paid": True}
Messages: Unexpected "N" (or "u", or "T").
Fix: JSON only has strings, numbers, true, false, null, objects and arrays, and the keywords are lowercase. Replace undefined and NaN with null (or remove the field), and write true/false in lowercase. Numbers also can't have leading zeros: a PIN like 007 must be the string "007".
10. Curly "smart" quotes
{“name”: “Priya”}
Messages: Expected a key in double quotes but found "“".
Fix: retype the quotes as straight ". Smart quotes sneak in when JSON is copied through Word, Google Docs, some chat apps or a phone keyboard. Copy from the original source or a code editor instead.
Two more you'll meet
- Two objects back to back (
{"a":1}{"b":2}): a JSON document has one top-level value. Wrap them in an array[{"a":1},{"b":2}], or, for log files with one object per line, check each line separately. - An invisible character at the very start. Some editors save files with a hidden byte-order mark. The formatter reports an unexpected character you can't see, with no line number; the visualizer ignores it. Re-save the file as UTF-8 without BOM.
A quick routine for fixing invalid JSON
- Click Format in the free JSON formatter and note the line and column.
- Look at that spot and just before it, including the end of the previous line.
- Fix one thing and format again. One mistake often hides the next.
- Still stuck? Paste into the free JSON visualizer for the plain-English hint and the marked line.
The full background on what valid JSON looks like is in how to format and validate JSON. YAML has its own set of traps; see common YAML syntax errors.
Check your JSON now
Paste it into the free JSON formatter, click Format, and fix what it points to. It's free, there's no sign-up, and your data never leaves your device.
Frequently asked questions
- Why is my JSON invalid?
- Most often a trailing comma, single quotes, a comment, an unescaped quote inside a string, or a missing comma or bracket. The formatter shows the line and column where it stopped reading.
- Are trailing commas allowed in JSON?
- No. Remove the comma after the last item in every object and array.
- Can JSON have comments?
- No. Remove
//and/* */comments, or store the note in a normal field. - How do I put a quote inside a JSON string?
- Escape it with a backslash:
\". The free string escaper does this for a whole block of text. - Why does the error point to the wrong line?
- The parser reports where it noticed the problem, which is usually just after the real mistake. Check the end of the line before.
Text tools
Try the JSON Formatter
Free, no sign-up, works in your browser. Paste JSON to check that it's valid, then format it with clear indentation or minify it to one line.
Also useful
- String Escape and UnescapeEscape text so it fits safely inside a JSON, JavaScript, CSV, SQL, regular expression or XML string, or turn escaped text like \n and \" back into plain text. The result updates as you type, ready to copy.
- JSON VisualizerPaste or open a JSON file up to 20 MB to explore it as a collapsible tree or as a graph of connected boxes. Search keys and values, copy the path to any field, and see exactly where invalid JSON breaks.