pttooz
← Blog

6 Common JSON Errors and How to Fix Them

JSON is invalid when the text breaks a syntax rule of RFC 8259, the JSON standard. 6 errors cause most broken JSON files: trailing commas, single-quoted strings, unquoted keys, comments, missing commas and values such as NaN or undefined.

Paste a file into the pttooz JSON Formatter and it shows the line and column of the first error, with a caret under the exact character.

1. Trailing commas

A comma after the last item in an object or array breaks JSON.

{ "name": "pttooz", "tools": 6, }

Fix: delete the comma before } or ].

{ "name": "pttooz", "tools": 6 }

JavaScript allows trailing commas, so this error often appears in JSON copied out of code.

2. Single quotes

JSON strings and keys need double quotes.

{ 'name': 'pttooz' }

Fix: replace every ' around keys and strings with ".

{ "name": "pttooz" }

3. Unquoted keys

Every key is a string, so every key needs double quotes.

{ name: "pttooz" }

Fix: wrap the key in double quotes: { "name": "pttooz" }.

4. Comments

Standard JSON has no comment syntax. // and /* */ cause a parse error.

{
  // tool count
  "tools": 6
}

Fix: remove the comment, or move the note into a field such as "_comment": "tool count". Config formats such as JSONC (used by VS Code) and JSON5 accept comments, but standard JSON parsers don’t.

5. Missing commas

Items in an object or array need a comma between them.

{ "name": "pttooz" "tools": 6 }

Fix: add a comma after "pttooz". The parser reports the error at the start of the next item, so look 1 item before the position it gives.

6. NaN, Infinity and undefined

JSON numbers must be finite, and JSON has no undefined.

{ "score": NaN, "limit": Infinity, "owner": undefined }

Fix: use null for missing values, or remove the field: { "score": null, "limit": null }.

JSON data types cheat sheet

JSON has 6 data types:

JSON type Example JavaScript Python
object { "a": 1 } Object dict
array [1, 2] Array list
string "text" String str
number 42, 3.14 Number int / float
boolean true, false Boolean bool
null null null None

A silent problem: large numbers

Not every JSON problem raises an error. JavaScript stores every JSON number as a 64-bit float, so integers above 9,007,199,254,740,991 (2^53 − 1) lose precision without warning. 9007199254740993 becomes 9007199254740992. Store large IDs as strings: "id": "9007199254740993".

Validate and format your JSON

Open the JSON Formatter and paste your file. It checks the syntax as you type, pinpoints the first error, formats with 2 spaces, 4 spaces or tabs, minifies for transfer and shows a tree view. The file stays in your browser, so it’s safe for files with API keys or customer data.