Tolket

Skip to content

Common JSON Errors and How to Fix Them (With Examples)

JSON looks like JavaScript, but its rules are much stricter. One stray comma or a single quote is enough to make an API call, a config file or a whole app fail. Here are the mistakes that cause almost every “invalid JSON” error, with the fix for each.

By Tolket Editorial Team 7 min read
Common JSON errors and how to fix them

The rules of valid JSON in 30 seconds

The fastest way to find a problem is to paste your data into our free JSON Formatter & Validator. It points to the exact line and column of the first error, and it runs in your browser so private data stays on your device.

1. Trailing commas

{ "name": "Ayesha", "age": 29, }

JavaScript tolerates the comma after the last item; JSON does not. Parsers report something like Unexpected token } or Expected double-quoted property name. Fix: delete the final comma in every object and array.

2. Single quotes

{ 'name': 'Ayesha' }

Fix: use double quotes for every key and string: { "name": "Ayesha" }.

3. Keys without quotes

{ name: "Ayesha" }

Valid in a JavaScript object, invalid in JSON. Fix: quote every key.

4. Comments

{
  "port": 8080 // default port
}

Standard JSON has no comments. Some tools accept a relaxed variant (often called JSONC or JSON5), but a strict parser will fail. Fix: remove the comment, or store the note as data, for example "_comment": "default port".

5. Missing commas between items

[ "red" "green", "blue" ]

Often caused by copying lines together. Fix: add the missing comma. If the validator points to the start of a line, the problem is usually at the end of the line above.

6. Unescaped characters inside strings

{ "path": "C:\Users\ayesha", "quote": "She said "hi"" }

Backslashes and double quotes inside a string must be escaped, and real line breaks are not allowed inside a string. Fix:

{ "path": "C:\\Users\\ayesha", "quote": "She said \"hi\"", "lines": "first\nsecond" }

7. Values that do not exist in JSON

undefined, NaN, Infinity, dates such as new Date(), functions and numbers with leading zeros (007) or a plus sign (+5) are all invalid. Fix: use null for missing values, write numbers plainly (7, 5) and store dates as strings, for example "2026-11-09T10:30:00Z".

8. Unclosed or mismatched brackets

{ "items": [ 1, 2, 3 }

Each { needs a matching } and each [ a matching ], closed in the right order. Fix: format the data with indentation; a missing bracket becomes obvious when the nesting looks wrong.

9. Smart quotes and invisible characters

JSON pasted from Word, Google Docs or a chat app may contain curly quotes such as “ and ” instead of straight ", non-breaking spaces or a hidden byte-order mark at the start of a file. The data looks right but will not parse. Fix: retype the quotes in a code editor, and save files as UTF-8 without BOM.

10. It is not JSON at all

Unexpected token < in JSON at position 0

This classic message means the response starts with <, usually an HTML error page (404, 500 or a login page) instead of the JSON you expected. Fix: open the request in your browser’s network tab, check the status code and the response body, and fix the URL, authentication or server error first.

How to avoid JSON errors in the first place

Frequently asked questions

Are trailing commas allowed in JSON?

No. Standard JSON does not allow a comma after the last item of an object or array, even though JavaScript does.

Can JSON contain comments?

Not in standard JSON. Formats such as JSONC (used by some editors’ settings files) and JSON5 allow them, but strict parsers and most APIs will reject them.

What does “position 0” in an error mean?

The parser failed at the very first character, which usually means the input is empty or is not JSON at all, such as an HTML page.

Are duplicate keys an error?

Most parsers accept them but keep only the last value, which can hide bugs. Treat duplicate keys as a mistake and remove them.

Tolket Editorial Team

We build free online tools and templates and write practical guides that help you get everyday digital tasks done faster.

Share this article
Scroll to Top