Skip to content

Security & Code

Common JSON Errors and How to Fix Them

By the Logicox team 3 min read

JSON looks like JavaScript, but its rules are much stricter. Code that a browser happily accepts as a JavaScript object can be invalid JSON, and a single stray character makes the whole file fail to parse. These are the errors developers hit most often, with a broken example and the fix for each.

1. Trailing comma

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

{ "name": "Ali", "age": 30, }

Fix: remove the comma before the closing } or ].

{ "name": "Ali", "age": 30 }

2. Single quotes

Strings and keys must use double quotes.

{ 'city': 'Lahore' }

Fix: { "city": "Lahore" }. If a value contains a double quote, escape it as \".

3. Keys without quotes

JavaScript lets you write { name: "Ali" }. JSON does not.

Fix: quote every key: { "name": "Ali" }.

4. Comments

JSON has no comments, neither // nor /* */.

{
  "debug": true // turn off in production
}

Fix: delete the comment. If you need notes in a config file, add a key such as "_note" or use a format that allows comments, such as JSONC or YAML, if your tool supports it.

5. Missing comma between items

Often caused by pasting two lines together.

{ "a": 1 "b": 2 }

Fix: add the comma: { "a": 1, "b": 2 }.

6. Missing colon after a key

{ "name" "Ali" }

Fix: { "name": "Ali" }.

7. Line breaks or tabs inside a string

A string must stay on one line. A real line break inside the quotes is invalid.

Fix: write a new line as \n and a tab as \t. A backslash itself must be doubled, so a Windows path becomes "C:\\Users\\Ali".

8. Values JSON does not have

undefined, NaN, Infinity, dates and functions are not JSON values. Numbers cannot have leading zeros (007) or a plus sign (+5), and hexadecimal such as 0xFF is not allowed.

Fix: use null for a missing value, write numbers plainly, and store dates as strings, for example "2026-11-11".

9. The file ends too early

A missing closing } or ], often after copying part of a larger response, makes the parser reach the end of the text while it is still expecting more.

Fix: format the JSON so nesting is indented, then look for the block that never closes.

10. Extra text after the JSON

Two objects one after the other, or a log line pasted after the data, is not valid JSON.

Fix: wrap several objects in an array, [{...}, {...}], or remove the extra text. Files where every line is its own object are a different format called JSON Lines.

Find the error in seconds

Paste your JSON into the JSON Formatter and tap Format. If it is invalid, you get a plain-English message such as “Trailing comma. Remove the comma before the closing } or ].” with the line and column, and Show me in the box jumps straight to the spot. Once it is valid, you can format it with 2 spaces, 4 spaces or tabs, sort the keys, or Minify it for production. The JSON never leaves your browser, so it is safe to paste API responses that contain keys or personal data.

Can’t find the tool you need?

Tell us what you’re looking for. We add new tools every month, and the most requested ones come first.

Request a tool