JSON Formatting and Validation Basics

The rules of valid JSON, the most common syntax errors, and when to format or minify JSON.

Updated Nov 2, 2026

JSON (JavaScript Object Notation) is the most common format for exchanging data between web services. It is easy to read, but strict: a single misplaced character makes a document invalid.

The rules in short

  • Data is made of objects { }, arrays [ ], strings, numbers, true, false and null.
  • Object keys must be strings in double quotes.
  • Strings use double quotes; special characters are escaped with a backslash, such as \n and \".
  • Items are separated by commas, with no trailing comma after the last item.
  • Comments are not allowed.

Common errors

ErrorInvalidValid
Single quotes{'a': 1}{"a": 1}
Trailing comma[1, 2, ][1, 2]
Unquoted key{a: 1}{"a": 1}
Leading zero{"n": 07}{"n": 7}

Format or minify?

Pretty-printed JSON, with indentation and line breaks, is easier for people to read and review. Minified JSON removes all optional whitespace, which makes it smaller to send over a network. The data is identical either way.

Keep secrets out of online tools

Choose tools that process JSON in your browser, and avoid pasting API keys or personal data into services that upload your input.