Skip to content
Toolbox

Developers

Common JSON Errors and How to Fix Them

The JSON mistakes behind most parse errors, such as trailing commas and single quotes, with fixes, plus tips for reading error messages and validating data.

Published · 5 min read

JSON is the most common format for sending data between programs, and it looks very similar to the objects you write in JavaScript. That similarity is exactly why mistakes are so common. A single misplaced comma or quote makes the whole document invalid, and the error message does not always point to the real problem. This guide lists the mistakes that cause most failures, shows how to fix them and explains how to read what a parser is telling you.

The strict rules of JSON in one minute

A JSON document is one value, usually an object in curly braces or an array in square brackets. Inside an object, every key is a string in double quotes, followed by a colon and a value, and the pairs are separated by commas. Values can be strings in double quotes, numbers, true, false, null, objects or arrays. That is all. Anything else is an error, even if JavaScript would accept it.

Mistake 1: a trailing comma

Programmers often leave a comma after the last item, because many languages allow it. JSON does not.

{
  "name": "Ayesha",
  "city": "Multan",
}

The comma after "Multan" must be removed. The same applies to the last element of an array.

Mistake 2: single quotes

Strings and keys must use double quotes. Single quotes are not valid.

{ 'name': 'Ayesha' }

Change every single quote that surrounds a key or a text value into a double quote. This often happens when data is copied out of source code or a log that prints objects.

Mistake 3: keys without quotes

JavaScript lets you write { name: "Ayesha" }, but JSON requires { "name": "Ayesha" }. Always wrap keys in double quotes.

Mistake 4: comments

JSON has no comment syntax. Lines that start with two slashes or blocks between slash and asterisk will make the document invalid. If you need notes in a configuration file, either use a format that supports comments or add a normal field, such as "note": "text", that the program ignores.

Mistake 5: missing commas or brackets

When you edit a long document by hand, it is easy to forget a comma between two pairs, or to delete a closing bracket. The parser usually complains about an unexpected character at the place where it noticed the problem, which is often just after the real mistake. Look at the line before the position it reports.

Mistake 6: values that JSON does not know

JSON has no undefined, no NaN and no Infinity. A value such as undefined is not allowed, and a computed number that has become NaN cannot be written. Use null for a missing value instead, or leave the key out. Dates are also just text in JSON, so they are normally written as a string such as "2026-12-03".

Mistake 7: numbers written the wrong way

Numbers cannot have leading zeros, so 007 is invalid, and they cannot be written with a plus sign or in hexadecimal. A number such as .5 must be written as 0.5. If a code like a postcode or a phone number can start with zero, store it as a string.

Mistake 8: raw line breaks and special characters inside strings

A line break inside a string must be written as backslash n, a tab as backslash t, and a double quote inside a string as backslash followed by the quote. Pasting a text with a real line break between the quotes makes the document invalid.

Reading the error message

Browsers and programs word their messages differently. You may see something like unexpected token, expected double-quoted property name, or unexpected end of data, usually with a position. Treat the position as a hint. Count back from it to the last comma, quote or bracket and check that part carefully. An unexpected end usually means a closing bracket or quote is missing.

Check and format your JSON with the tool

Our free JSON Formatter validates your text and lays it out in a readable way. It uses your browser's own parser, so it applies the same strict rules, and nothing is uploaded.

  1. Paste the text into the input box.
  2. Press Format to indent it with two spaces, four spaces or tabs, or Minify to remove all extra space.
  3. If it is invalid, read the message shown below the buttons and fix the spot it points to. If it is valid, copy the result.
  4. Tick the option to sort keys from A to Z when you want to compare two documents. The order of items inside arrays is never changed.

Very large numbers

Browsers read JSON numbers as ordinary floating-point numbers, which can represent whole numbers exactly only up to a certain size. Identifiers with more than about 15 digits can be rounded silently. If you work with long IDs, store them as strings. The tool warns you when a number in your input has more digits than can be kept exactly.

Habits that prevent most errors

  • Generate JSON with a library function instead of building it by joining strings.
  • Validate data before you send it and before you trust data you receive.
  • Pretty-print data while you debug, and minify it when you ship it.
  • If a value arrives encoded, for example as Base64, decode it first with the Base64 tool and then format what is inside.

Most invalid JSON turns out to be one of the mistakes above, and once you know them, finding the problem takes seconds instead of an afternoon.

Try it yourself

Free, private and it runs in your browser.

More guides