What Is JSON? Syntax Rules and How to Fix Common Errors

By Jasveer Raj · Updated 2026-11-01

Quick answer

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. It is the standard format for most web APIs and many configuration files.

The building blocks

  • Objects: key and value pairs inside curly braces, such as {"name": "Asha"}.
  • Arrays: ordered lists inside square brackets, such as [1, 2, 3].
  • Values: strings, numbers, true, false, null, objects or arrays.

Syntax rules

  1. Keys and strings must use double quotes.
  2. Items are separated by commas, with no comma after the last item.
  3. No comments are allowed.
  4. Numbers cannot have leading zeros, and special values such as undefined are not allowed.

The most common errors

  • Trailing comma: {"a": 1,} is invalid. Remove the last comma.
  • Single quotes: {'a': 1} is invalid. Use double quotes.
  • Unquoted keys: {a: 1} is valid JavaScript but not valid JSON.
  • Missing bracket or quote: the parser reports an unexpected end of input.
  • Comments: remove // and /* */ before parsing.

How to debug quickly

  1. Paste the text into a JSON formatter and run Format.
  2. Read the reported line and column, which point to where parsing failed.
  3. Look just before that position, because the actual mistake is often the previous character.
  4. Fix it and format again until the output is valid.

Formatting versus minifying

Formatting adds indentation and line breaks so people can read the data. Minifying removes all unnecessary whitespace to make payloads smaller. Both versions represent identical data.

FAQ

Is JSON the same as a JavaScript object?

No. JSON is a strict text format with stricter rules. Objects in JavaScript code can have unquoted keys, single quotes and trailing commas.

Is it safe to paste JSON into an online formatter?

Only if the tool runs in your browser and does not upload it. Avoid pasting secrets into tools that send data to a server.

Try the free JSON formatter and validator below.

Try the calculator

Esc