Guide — JSON Formatter & Validator

Common JSON Errors and How to Fix Them

The JSON syntax errors that break parsers most often — trailing commas, single quotes, unquoted keys, comments, bad escapes — with error messages, examples and fixes.

Updated 3 min read
Calculate it instantly
JSON Formatter & Validator

Beautify, minify and validate JSON with precise error locations. Your data never leaves your browser.

Open the JSON formatter →

JSON is strict. A single misplaced comma makes the whole document invalid, and error messages like Unexpected token } in JSON at position 147 aren’t always helpful. Here are the errors you’ll hit most often and exactly how to fix them.

Paste your JSON into the JSON formatter and press Validate: it reports the error with the line and column, so you can jump straight to the problem.

1. Trailing commas

Invalid:

{
  "name": "Ada",
  "age": 36,
}

Fix: remove the comma after the last item. JavaScript allows trailing commas; JSON doesn’t. The same rule applies to arrays: [1, 2, 3,] is invalid.

2. Single quotes

Invalid:

{ 'name': 'Ada' }

Fix: JSON requires double quotes for both keys and string values:

{ "name": "Ada" }

3. Unquoted keys

Invalid:

{ name: "Ada" }

Fix: every key must be a double-quoted string: "name". This error is common when copying JavaScript object literals.

4. Comments

Invalid:

{
  // user settings
  "theme": "dark"
}

Fix: standard JSON has no comments. Remove them, or move notes into a field such as "_comment": "user settings". Formats like JSONC (used by VS Code settings) and JSON5 allow comments, but standard parsers will reject them.

5. Missing commas

Invalid:

{
  "name": "Ada"
  "age": 36
}

Fix: add a comma between properties. The parser usually reports the error at the start of the next line, so look at the line before the reported position.

6. Missing or extra brackets

Unexpected end of JSON input almost always means a missing } or ]. Formatting helps: once indented, the mismatched level stands out. Count opening and closing brackets, or format what you have and look for where the indentation goes wrong.

7. Invalid values

Invalid Valid
True, False true, false
NULL, None, undefined null
NaN, Infinity Use null or a string
.5, 05 0.5, 5
0x1F 31

8. Bad escape sequences

Inside strings, backslashes must be escaped, and only certain escapes are allowed: \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX.

Invalid: "path": "C:\Users\ada" Valid: "path": "C:\\Users\\ada"

Literal line breaks inside a string are also invalid; use \n.

9. Smart quotes

Copying from Word, Google Docs or chat apps can replace " with curly quotes “ ”, which parsers don’t recognise. Replace them with straight double quotes.

10. Byte-order mark or invisible characters

Files saved with a BOM, or text with zero-width spaces, can fail at “position 0”. Re-save the file as UTF-8 without BOM, or paste it into a plain-text editor and copy it back.

A debugging routine

  1. Validate to get the line and column.
  2. Look at that line and the line before it.
  3. Format what parses to see the structure.
  4. Fix one error at a time and re-validate; one mistake can cause misleading follow-on errors.

For a refresher on valid syntax, read JSON Syntax Basics: A Beginner's Guide With Examples. Try fixing the examples above in the formatter below.

Try it: JSON Formatter & Validator

JSON formatter & validatorReady

Put this into practice
JSON Formatter & Validator

Beautify, minify and validate JSON with precise error locations. Your data never leaves your browser.

Open the JSON formatter →