Skip to content
JSON Viewer

Guide

Common JSON Syntax Errors and How to Fix Them

Most invalid JSON comes from a small set of mistakes. Nearly all of them happen because JSON looks like a JavaScript object but follows stricter rules. Below are the eight errors we see most often, with a broken example and the fix for each.

Paste any of the broken examples into the JSON validator to see the error flagged on its exact line, or press Fix in the JSON repair tool to correct it automatically.

1. Trailing commas

JSON does not allow a comma after the last item in an object or array.

{ "name": "Ada", "langs": ["en", "fr",], }

Fix: remove the comma before every ] and }.

{ "name": "Ada", "langs": ["en", "fr"] }

2. Single quotes

Strings and keys must use double quotes. Single quotes are a JavaScript habit.

{ 'name': 'Ada' }

Fix: { "name": "Ada" }. Watch out for curly “smart quotes” pasted from documents too. They look similar but are not valid either.

3. Unquoted keys

Every key must be a double-quoted string, even simple ones.

{ name: "Ada", age: 36 }

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

4. Comments

Standard JSON has no comments. // and /* */ are only allowed in JSONC or JSON5 files, such as VS Code settings.

{
  // the user's name
  "name": "Ada"
}

Fix: delete the comments, or store notes in a field such as "_comment". See JSON vs JSONC vs JSON5 for when comments are allowed.

5. Missing commas

Each item in an object or array must be separated by a comma. This usually happens when you add a new line to a list.

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

Fix: add a comma after "Ada". The validator reports this error on the line after the missing comma, because that is where the parser hits an unexpected token.

6. Unclosed brackets or strings

A missing }, ] or closing " makes the parser read to the end of the input.

{ "users": [ { "name": "Ada" } }

Fix: close the array with ] before the final }. Format the JSON so nesting is easy to see; the editor’s bracket matching highlights the partner of the bracket under your cursor.

7. Invalid values

JSON allows only true, false and null in lowercase. undefined, NaN, Infinity, and Python’s True, False and None are invalid.

{ "active": True, "score": NaN, "parent": None }

Fix: { "active": true, "score": null, "parent": null }

8. Bad escapes and raw control characters

Inside a string, backslashes must start a valid escape (\", \\, \/, \b, \f, \n, \r, \t, \uXXXX). Raw tabs and line breaks are not allowed.

{ "path": "C:\new\folder" }

Fix: escape the backslashes: { "path": "C:\\new\\folder" }

Reading “Unexpected token” messages

Browsers report errors like Unexpected token } in JSON at position 42. The position counts characters from the start of the text, which is hard to find by hand. Our viewer converts it to a line and column, underlines the spot, and tells you what it expected instead.