Common JSON Errors and How to Fix Them (8 Mistakes to Check First)

JSON looks simple, which is exactly why a single misplaced character can break it. If you have ever pasted a block of data into an app or an API and received a vague message such as “Unexpected token” or “Parse error at line 1”, you already know the frustration. The good news is that almost every broken JSON file fails for one of a small number of reasons. This guide walks through the eight mistakes we see most often, shows what the problem looks like, and explains how to fix it.

The quickest way to follow along is to open the free JSON Formatter and Validator in another tab, paste your data, and let it point at the problem. If you are new to the format, our guide on how to format and minify JSON online is a good starting point.

A quick reminder of the JSON rules

JSON is a text format for structured data. A valid document is built from only a few pieces: objects written with curly braces, arrays written with square brackets, strings in double quotes, numbers, the words true and false, and null. Objects hold key and value pairs separated by commas, and every key must be a string. That is nearly all there is, but the format is strict. Unlike JavaScript, it does not forgive shortcuts.

1. A trailing comma after the last item

This is the number one cause of invalid JSON. Programmers are used to leaving a comma after the final item because many languages allow it. JSON does not.

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

The comma after 30 makes the whole document invalid. Remove it and the data parses correctly. The same rule applies to arrays: [1, 2, 3,] is not valid.

2. Single quotes instead of double quotes

Strings and keys in JSON must use double quotation marks. Single quotes are fine in many programming languages, but a JSON parser will reject them.

{ 'city': 'Riyadh' }   // invalid
{ "city": "Riyadh" }   // valid

This mistake often appears when data is copied from code or from a message that was typed by hand.

3. Keys without quotes

In JavaScript you can write { name: "Ali" }. In JSON every key needs quotes, so the correct version is { "name": "Ali" }. If you copied an object from a JavaScript file, this is one of the first things to check.

4. Comments inside the data

JSON has no comment syntax. Lines that start with // or blocks wrapped in /* */ will cause an error. If you need to explain a value, either remove the comment before you use the data or add a normal field such as "note": "this value is in kilograms". Some tools accept a relaxed format that allows comments, but standard JSON does not.

5. Missing or mismatched brackets and braces

Every opening { needs a closing }, and every [ needs a matching ]. In long documents with several levels of nesting it is easy to lose count. A formatter helps here because it indents each level. When the structure looks wrong after formatting, or the tool reports an unexpected end of data, you are probably missing a closing bracket near the end of the file.

6. Missing commas between items

The opposite of the trailing comma problem is forgetting the comma between two items.

{
  "first": "Sara"
  "last": "Khan"
}

Here a comma is needed after "Sara". Parsers usually report the error at the start of the next line, so look at the line just above the one mentioned in the message.

7. Unescaped special characters inside strings

Some characters cannot appear raw inside a JSON string. A double quote must be written as \", a backslash as \\, and a line break as \n. Windows file paths are a classic trap: "C:\Users\Ali" is invalid because \U is not a recognised escape. Write it as "C:\\Users\\Ali" instead. A real line break typed inside a string value will also break parsing.

8. Values that JSON does not support

JSON allows strings, numbers, booleans, null, objects and arrays. It does not allow undefined, NaN, Infinity, functions or dates as native types. Numbers also cannot have leading zeros, so 007 is invalid. If you need a date, store it as a string such as "2026-12-04". If you need a number with leading zeros, such as a postal code, store it as a string too.

How to find the exact problem quickly

  1. Paste the data into the JSON validator and run the check.
  2. Read the line and position in the error message. Remember that the real mistake is often on the previous line.
  3. Fix one error at a time and validate again. A single missing comma can hide other problems further down.
  4. When the data is valid, use the format option to indent it so it is easy to read, or minify it when you need the smallest possible size.

Your data stays in your browser while you do this. ToolRazo runs its tools locally, as explained in our Privacy Policy, which is helpful when the data contains something private.

Tips to avoid JSON errors in the first place

  • Generate JSON with code (for example, a built-in serialiser) instead of writing it by hand whenever you can.
  • Keep your editor’s JSON mode switched on so it highlights mistakes as you type.
  • Validate data before sending it to an API or saving it to a file.
  • When copying from a web page or chat app, check that smart or curly quotation marks have not replaced straight ones. Curly quotes are not valid in JSON.

Frequently asked questions

What does “Unexpected token” mean in JSON?

It means the parser found a character it did not expect at that position. Common causes are a trailing comma, a single quote, a missing comma or text before the first bracket.

Can JSON contain comments?

No. Standard JSON has no comment syntax. Remove comments before parsing, or store notes as regular fields.

Is an empty object or array valid JSON?

Yes. {} and [] are both valid documents.

Why does my JSON work in JavaScript but fail in a validator?

JavaScript object literals are more relaxed than JSON. They allow unquoted keys, single quotes and trailing commas, while JSON does not.

What is the difference between formatting and minifying JSON?

Formatting adds indentation and line breaks so people can read the data. Minifying removes all unnecessary whitespace to reduce size. The data itself stays the same.

Is it safe to paste private data into an online JSON tool?

That depends on the tool. The ToolRazo formatter runs in your browser and does not upload your text. Even so, avoid pasting passwords or secret keys into any website out of habit.

Next time a parser complains, run through the eight checks above. In most cases you will find the problem in under a minute.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top