💻 Developer Tools

The 7 Most Common JSON Errors and How to Fix Them

Unexpected token? Trailing comma? Learn the seven JSON mistakes that break APIs and config files, what the error messages mean, and how to fix each one.

In this article
  1. 1. Trailing commas
  2. 2. Single quotes
  3. 3. Unquoted keys
  4. 4. Comments
  5. 5. Missing commas or brackets
  6. 6. Invalid values
  7. 7. Unescaped characters in strings
  8. Debugging checklist
  9. Bonus: format vs minify
  10. Validate privately

JSON (JavaScript Object Notation) is the language of APIs, config files and app data. It’s simple — but strict. One misplaced comma and the whole thing fails with a cryptic message like “Unexpected token } in JSON at position 42”. Here are the seven mistakes behind most of those errors.

1. Trailing commas

{
  "name": "Toolsopedia",
  "tools": 72,
}

The comma after 72 has nothing after it. JavaScript tolerates this; JSON doesn’t.

Fix: remove the comma after the last item in every object {} and array [].

2. Single quotes

{ 'name': 'Toolsopedia' }

Fix: JSON requires double quotes for both keys and string values: { "name": "Toolsopedia" }.

3. Unquoted keys

{ name: "Toolsopedia" }

Fix: every key must be a double-quoted string: { "name": "Toolsopedia" }.

4. Comments

{
  // number of tools
  "tools": 72
}

Fix: remove comments. If you need notes, add them as data: "_note": "number of tools".

5. Missing commas or brackets

{
  "name": "Toolsopedia"
  "tools": 72
}

A missing comma between items, or an unclosed { or [, is the most common error in hand-edited files.

Fix: format the JSON with indentation — mismatched brackets and missing commas become obvious when every item sits on its own line.

The line and column in an error message show where the parser gave up, which is often just after the real mistake. Look at the end of the previous line first.

6. Invalid values

JSON supports only these value types: string, number, true, false, null, object and array. These are not allowed:

InvalidUse instead
undefinednull or omit the key
NaN, Infinitynull or a string
True, FALSEtrue, false (lowercase)
0123 (leading zero)123 or "0123" as a string
.50.5

7. Unescaped characters in strings

Quotes, backslashes and line breaks inside a string must be escaped:

{ "path": "C:\new\folder", "quote": "She said "hi"" }

Fix:

{ "path": "C:\\new\\folder", "quote": "She said \"hi\"" }

Line breaks inside strings must be written as \n.

Debugging checklist

  1. Paste the JSON into a formatter and read the error’s line and column.
  2. Check the line before the reported position.
  3. Look for trailing commas, single quotes, missing commas and comments.
  4. Format with indentation to see the structure clearly.
  5. Validate again until it parses.

Bonus: format vs minify

  • Formatted (pretty-printed) JSON is easy for humans to read and debug.
  • Minified JSON removes whitespace to make files smaller for sending over networks.

Both contain exactly the same data.

Validate privately

Our JSON Formatter beautifies, minifies, sorts keys and validates JSON — showing the error with its line and column. It runs in your browser, so API responses with tokens or personal data are never sent anywhere.

Free toolTry the JSON FormatterBeautify, validate or minify JSON with clear error messages.

Frequently asked questions

Why does my JSON work in JavaScript but fail in JSON.parse?

JavaScript object literals allow single quotes, unquoted keys, trailing commas and comments. JSON doesn't. Paste it into a validator to find the differences.

Can JSON have comments?

Standard JSON can't. Some tools accept variants like JSONC or JSON5 for config files, but APIs expect strict JSON.

What's the difference between null and an empty string?

null means 'no value'; "" is a string with zero characters. Both are valid JSON, but APIs may treat them differently.

Written by the Toolsopedia team. Spotted an error? Tell us and we’ll fix it.

Keep reading

💻 Developer Tools HEX, RGB and HSL Colour Codes Explained Understand HEX, RGB and HSL colour codes, how to convert between them, when designers use each, and how to choose text colours with enough contrast. 💻 Developer Tools Static vs Dynamic QR Codes: Which Should Your Business Use? Static QR codes never expire and need no subscription; dynamic ones can be edited and tracked. Learn the differences, costs and when to use each. 🧮 Calculators 5 Percentage Formulas You Will Use Every Week Master the five percentage calculations behind discounts, marks, salary hikes, price changes and GST — with simple formulas, mental shortcuts and examples.