← All guides

What is JSON? The rules and the most common mistakes

· 2 min read

JSON is the most common format for carrying data as text. Its rules are few but strict: even one extra comma makes the whole file invalid.

A JSON example

In JSON objects are written with curly braces and arrays with square brackets. Values can be a string, a number, true, false, null, an object or an array.

{
  "name": "Alice",
  "age": 28,
  "active": true,
  "languages": ["English", "French"],
  "address": null
}

The most common mistakes

  1. A comma after the last item: {"a": 1,} is invalid.
  2. Using single quotes: {'a': 1} is invalid. JSON always needs double quotes.
  3. Leaving a key without quotes: {a: 1} is invalid. Keys must be double-quoted strings too.
  4. Adding comments: // note or /* note */ do not exist in JSON.
  5. Writing true, false and null in capitals: True or NULL is invalid, always lowercase.
  6. A leading zero in a number: 007 is invalid. The number should be 7, or write it as a string "007".
  7. An unescaped double quote or line break inside a string: "Al "Bo"" is wrong. The right form is "Al \"Bo\"".
  8. Forgetting the comma between members: {"a": 1 "b": 2} is invalid.

Watch out for large numbers

If you work with JavaScript, integers larger than 9,007,199,254,740,991 (2^53 − 1) cannot be stored exactly. An ID above that limit can be silently corrupted. It is safer to send such numbers as strings ("12345678901234567890"). Our tools warn you when they see a number longer than 16 digits.

Formatting and minifying

You use the indented (pretty) form to read and the single-line minified form to send. Both are the same data. The JSON formatter does both, can sort keys alphabetically and shows the line and column of the error in invalid JSON. Your data never leaves your browser.

JSON or CSV?

For flat, table-like data CSV is smaller and works with Excel. For nested data with a varying structure JSON is the better fit. If you need to tidy a CSV, see the CSV cleaner.

More guides