The Rules JSON Actually Enforces

  • Objects and arrays are wrapped in {} and [].
  • Keys are always in double quotes. Single quotes are invalid.
  • Strings use double quotes, and a literal quote inside must be escaped as \".
  • No trailing commas after the last item in an object or array.
  • Only true, false and null are allowed as bare values.
  • No comments. JSON does not support them.

Our JSON Formatter checks all of these and reports the exact position of the first failure.

The Five Errors That Cause Most Failures

1. Trailing commas

A comma after the final key or array element is the most common mistake by a distance. {"a":1,} is invalid; it must be {"a":1}.

2. Single quotes instead of double quotes

Python, PHP and JavaScript object literals all accept single quotes, so code copied out of a script often fails as JSON. Search and replace every ' that delimits a key.

3. Smart quotes pasted from a document

Text copied from Word, Google Docs or a messaging app often contains typographic quotes. They look identical to real quotes but are different characters, and no parser accepts them.

4. Unescaped newlines and backslashes

A string cannot contain a raw line break. Use \n for a newline and \\ for a literal backslash, such as in Windows file paths.

5. Comments

Many config files allow comments and JSON does not. Remove every // and /* */ before validating.

Minify or Pretty-Print?

Pretty-printing adds indentation and line breaks, which makes a file readable to a person and usually larger on disk. Minifying strips all of that, which makes it smaller and often faster to load. Use pretty format while you are editing, and minify before shipping JSON to a browser.

The same tool handles both directions: format a minified file to inspect it, then minify it again before use.

Reading an Error Message

Most parsers report a position, not a cause. A pointer at line 3, column 24 usually means look at the character just before that point, which is very often the unexpected comma or the missing closing bracket. Validating after every small edit turns a long debugging session into an immediate, precise error.

Frequently Asked Questions

What is the most common JSON error?
A trailing comma after the last item in an object or array. It is the single most frequent cause of a file being rejected.
How do I fix invalid JSON quickly?
Run it through a validator to get the exact line and column, then inspect the character just before that point. Validating after each small edit keeps errors small.
Does JSON allow comments and single quotes?
No. JSON permits only double-quoted keys and strings, and it has no comment syntax. Both are common causes of invalid files.

Related Tools

Amazon

Shop for calculators and productivity tools on Amazon — great deals for every need.

Shop on Amazon →