JSON Formatter & Validator

Pretty-print messy JSON, minify it again, and get the exact line where a syntax error is.

Result

          
Keys
Max depth
Output size

How to use it

  1. Paste your JSON into the left box — it is validated as you type.
  2. Press Beautify to format it, or Minify to strip every space.
  3. Copy the result, or download it as a .json file.

The four mistakes that break almost every JSON file

JSON is strict in ways that trip up anyone used to writing JavaScript by hand. Nearly every invalid file is one of these four:

  • A trailing comma. {"a": 1, "b": 2,} is valid JavaScript and invalid JSON. This is the most common one by a wide margin.
  • Single quotes. JSON strings must use double quotes. {'a': 1} is not JSON.
  • Unquoted keys. {a: 1} is a JavaScript object, not JSON. Every key needs double quotes.
  • Comments. JSON has none. No // and no /* */, however reasonable that seems in a config file.

Two smaller ones worth knowing: NaN and Infinity are not valid JSON numbers, and a stray byte-order mark at the very start of a file — invisible in every editor — will fail to parse with an error that makes no sense.

Beautify or minify, and when each is right

Beautify when a human has to read it: debugging an API response, reviewing a config file, or trying to see the shape of data somebody sent you. Indentation is the whole point.

Minify when a machine has to move it. Stripping the spaces and line breaks often removes a fifth of the file size, which matters for anything sent over a network repeatedly. Neither operation changes your data by a single character — only the whitespace between it.

Frequently asked questions

Why does it say my JSON is invalid when it looks fine?

The three usual culprits are a trailing comma after the last item, single quotes instead of double quotes, and keys that are not quoted at all. JavaScript object syntax allows all three; JSON does not.

What does the line number refer to?

The line in your input box, counting from 1. The tool converts the browser's character position into a line and column so you can find it without counting.

Is my data sent to a server?

No. JSON.parse and JSON.stringify are built into your browser, so the whole job happens locally. You can safely paste an API response containing private data.

What is max depth telling me?

How many levels of nesting the deepest branch has. A flat object is 1. Deeply nested JSON (over about 6) is usually a sign the shape could be flattened.

Does minifying change my data?

No. It removes only whitespace between tokens. The parsed result is identical — it is just smaller to transmit.

Related tools