Back to All Tools

JSON Formatter & Validator

Format, beautify, minify and validate JSON data.

100% Private — Your data never leaves your browser. Everything runs locally on your device.

Using the formatter

  1. Paste your JSON into the Input JSON box. It can be an API response, a config file or a log line.
  2. Beautify puts each value on its own line with 2 spaces per level. The result appears in the Output box.
  3. Minify removes every space and line break that is not inside a string. The result is one line.
  4. Validate only checks the input. It does not change the Output box.
  5. Read the line under the buttons. It shows ✓ Valid JSON in green, or the error message in red. An orange note below it warns about valid JSON that changes when it is read, such as very large numbers or duplicate keys.
  6. Copy copies the Output box. The button reads Copied! for a moment when it works.

Some things to know before you start:

Reading the error message

The tool does not write its own error messages. It shows the message from your browser's built-in JSON.parse. In Chrome and Edge, the message comes in one of two forms.

With a position. For example:

Expected double-quoted property name in JSON at position 16 (line 1 column 17)

Position counts characters from 0. Line and column count from 1. For long input, go to the line number and count across.

With a piece of your text. For example:

Unexpected token 'N', "{"a": NaN}" is not valid JSON

This form names the bad character and shows the text around it, but no position. Search your input for that text to find the spot.

Firefox and Safari word their messages differently. Firefox also gives a line and column. Safari's messages are shorter and may not say where the problem is. If you cannot find an error, try the same input in Chrome or Firefox.

One more thing: the reported spot is where the parser gave up. The real mistake is often just before it, on the same line or the line above.

The most common JSON errors

Each example below shows the broken JSON, the fixed version, and the message Chrome gives for it.

1. Trailing comma

A comma after the last item is fine in JavaScript, but not in JSON.

Broken: {"a": 1, "b": 2,}
Fixed:  {"a": 1, "b": 2}

Message: Expected double-quoted property name ... (line 1 column 17). Column 17 is the } right after the extra comma. In an array, [1, 2, 3,] gives Unexpected token ']'.

2. Single quotes

Broken: {'name': 'Asha'}
Fixed:  {"name": "Asha"}

Message: Expected property name or '}' in JSON at position 1. JSON strings and keys need double quotes. An apostrophe inside a string is fine: "it's".

3. Keys without quotes

Broken: {name: "Asha"}
Fixed:  {"name": "Asha"}

You get the same message as for single quotes. Every key must be a string in double quotes.

4. Comments

Broken:
{
  "a": 1 // note
}

Message: Expected ',' or '}' after property value ... (line 2 column 10). Column 10 is the first /. JSON has no comments of any kind. Delete them, or move the note into a normal key such as "_note".

5. Missing comma between items

Broken:
{
  "a": 1
  "b": 2
}

Message: Expected ',' or '}' after property value ... (line 3 column 3). The message points at "b" on line 3, but the comma is missing at the end of line 2. This is the most common case where the real mistake is one line above.

6. NaN, undefined, Infinity or True

Broken: {"a": NaN, "b": undefined, "ok": True}
Fixed:  {"a": null, "b": null, "ok": true}

Message: Unexpected token 'N'. JSON only has true, false and null, all in lower case. Use null for a missing value, or leave the key out.

7. Curly quotes pasted from a document

Broken: {“name”: “Asha”}
Fixed:  {"name": "Asha"}

Message: Expected property name or '}' in JSON at position 1. Word processors, chat apps and some websites change straight quotes into curly ones. They look almost the same. Retype the quotes, or use find and replace in a plain text editor.

8. Line breaks and backslashes inside strings

A real line break inside a string gives Bad control character in string literal. Write \n instead. A Windows path such as "C:\path" gives Bad escaped character, because a single backslash starts an escape. Double it: "C:\\path".

What Beautify and Minify can change

Both buttons read your JSON with JSON.parse and write it again with JSON.stringify. So the output is rebuilt, not just re-spaced. For most JSON you will not notice. But these cases do change:

If you only want to check the JSON and keep the original text exactly as it is, use Validate.

When to beautify and when to minify

Beautify when a person needs to read the JSON, for example to debug an API response or review a config change. Minify when a program reads it, for example a single-line environment variable, or when you want a smaller file. Minify only removes the spaces between values. Spaces inside strings stay. The changes listed in the section above happen with both buttons.

JSON is not a JavaScript object

JSON looks like JavaScript, but it is much stricter. A JavaScript object can use single quotes, keys without quotes, trailing commas, comments, undefined and functions. JSON allows none of them. So an object copied from JavaScript code often fails here. If you have the object in a browser console, run JSON.stringify(yourObject, null, 2) there. It prints valid JSON, but it leaves out keys whose value is undefined or a function.

Frequently Asked Questions

Why did my long ID number change after formatting?

JavaScript stores numbers exactly only up to 9,007,199,254,740,991. Larger whole numbers are rounded when the tool reads them. For example, 12345678901234567890 becomes 12345678901234567000. The tool shows an orange note when it finds such a number. Store long IDs as strings so they stay exact.

Can I choose 4 spaces or tabs for the indent?

No. Beautify always uses 2 spaces per level, and Minify puts everything on one line. If you need a different indent, copy the result into a code editor and change the indent setting there.

Why does the error point to the wrong line?

The message shows where the parser gave up, not where the mistake is. A missing comma at the end of line 2 is reported at the start of line 3. Look at the reported spot and the few characters just before it.

Does Validate find duplicate keys?

Yes, as a note. Duplicate keys are allowed by the browser's JSON parser, so the JSON still counts as valid. But the tool shows an orange note with the first duplicate key and its line. Beautify and Minify keep only the last value for each key.

Is my JSON sent to a server?

No. The tool uses the JSON.parse and JSON.stringify functions built into your browser. The JSON you paste stays in the page and is not sent anywhere.