How to format and validate JSON

Format messy JSON into readable, indented text, validate it, and fix the most common syntax errors: trailing commas, single quotes, unquoted keys and comments.

Why format and validate JSON

JSON (JavaScript Object Notation) is the most common format for APIs, configuration files and data exchange. Machines often produce it as a single long line, which is efficient to send but almost impossible to read. Formatting, also called pretty printing or beautifying, adds line breaks and indentation so you can see the structure. Validation checks that the text follows JSON's strict syntax, so a parser will accept it. A single missing comma can break an entire configuration file or API request.

JSON syntax rules in brief

  • A JSON document is one value: an object, array, string, number, true, false or null.
  • Objects use curly braces and contain key-value pairs: {"name": "Ada", "age": 36}.
  • Keys must be strings in double quotes.
  • Arrays use square brackets: [1, 2, 3].
  • Items are separated by commas, with no comma after the last item.
  • Strings use double quotes only. Quotes, backslashes and control characters inside them must be escaped, for example \" and \n.
  • Numbers are plain decimals, such as -12, 3.14 or 1e6. Leading zeros, NaN and Infinity are not allowed.
  • Comments are not part of JSON.

How to format JSON

  1. Open the JSON formatter.
  2. Paste your JSON, or open or drop a .json file.
  3. Choose the indentation: 2 spaces, 4 spaces or tabs. Choose Minify for the most compact output.
  4. If the input is valid, the formatted result appears and the status bar shows Valid JSON.
  5. Copy the result or download it as a .json file.
JSON formatterFormat and validate JSON in your browser, with nothing uploaded.

How to validate JSON and find the error

The JSON validator uses the same engine. When the input is invalid, it shows an error message instead of output. In most browsers the message points to the line and column where parsing stopped, for example Invalid JSON at line 4, column 3. The real mistake is often just before that point: a missing comma on the previous line will be reported at the start of the next key.

Validation here means syntax validation. The tool checks that your text is well-formed JSON; it does not check it against a JSON Schema or confirm that the fields your application expects are present.

JSON validatorCheck JSON and see the line and column of any syntax error.

The most common JSON errors and how to fix them

Trailing commas

JavaScript allows a comma after the last item, JSON does not. {"a": 1, "b": 2,} is invalid. Remove the comma before the closing brace or bracket.

Single quotes

{'name': 'Ada'} is valid JavaScript but not JSON. Replace single quotes with double quotes around keys and strings. Watch for curly quotes as well, which word processors and chat apps often insert in place of straight quotes.

Unquoted keys

{name: "Ada"} fails because keys must be quoted. Write {"name": "Ada"}.

Comments

Lines starting with // or blocks in /* */ are not allowed. Remove them, or move the notes into a field such as "_comment". If you need comments in configuration, consider JSONC where your tools support it, or YAML.

Missing commas and brackets

Every item except the last needs a comma, and every opening brace or bracket needs a matching closing one. Formatting the part that does parse, or checking the reported line, usually reveals the gap.

Invalid values

undefined, NaN, Infinity, functions and dates are not JSON values. Use null, a number, or a string such as an ISO 8601 date like "2026-01-01T00:00:00Z".

Unescaped characters in strings

A raw line break or tab inside a string is invalid. Use \n and \t. A Windows path needs doubled backslashes: "C:\\Users\\Ada".

Things to know before reformatting

Our formatter parses your JSON and writes it out again, which has a few side effects that are standard for JavaScript-based tools:

  • Integers larger than 9,007,199,254,740,991 (2 to the power of 53, minus 1) cannot be stored exactly and may change. Keep very large IDs as strings.
  • If an object contains the same key twice, only the last value is kept.
  • Escape sequences such as \u00e9 are written out as the actual character, é. The meaning is unchanged.
  • Key order is preserved, with one exception from JavaScript: keys that look like non-negative integers, such as "1" or "42", are moved to the front in numeric order.

Minify JSON for production

Minifying removes all whitespace that is not inside strings. The data is identical but smaller, which helps for payloads, embedded config and storage. Use formatted JSON for files people edit and review, and minified JSON for transmission. Most web servers also compress responses with gzip or Brotli, which narrows the size difference.

JSON minifierStrip whitespace from JSON to make it as compact as possible.

Formatting JSON in other places

A browser tool is quickest for one-off checks, but it helps to know the alternatives for repeated work:

  • Most code editors, including VS Code, can format a .json file with a built-in command and highlight syntax errors as you type.
  • On the command line, jq . file.json pretty prints a file, and python3 -m json.tool file.json does the same without extra installs.
  • In JavaScript, JSON.stringify(value, null, 2) produces two-space indentation.
  • Many projects run a formatter such as Prettier in CI, so committed JSON always has the same style.

Whatever tool you use, keep one indentation style per project. Mixed formatting creates noisy diffs in code review.

Privacy when working with JSON

API responses and config files often contain tokens, customer data or internal URLs. Our JSON tools run entirely in your browser, so the text you paste is not uploaded or stored. It is still good practice to remove secrets before sharing formatted JSON in tickets, chats or screenshots.

Find your next tool
↑ ↓ · Enter ↵Esc · Close search