Developer tool · free · runs in your browser

JSON Formatter and Validator

Paste JSON to check it and reformat it. Valid input is pretty printed, minified or sorted. Invalid input gets the line, the column and a clear reason, such as a trailing comma or single quotes.

What this JSON formatter and validator does

Paste JSON from an API response, a log line or a config file and the tool checks it against the JSON standard. If it is valid, you get it back pretty printed with 2 spaces, 4 spaces or tabs, minified to a single line, or with every object's keys sorted. If it is not valid, you get the line and column of the first problem, the offending line with a caret under the spot, and a plain description of what is wrong.

How to use it

  1. Paste JSON into the box. Validation starts as you type.
  2. Choose the output style.
  3. If the input is invalid, fix the reported spot and the result refreshes.
  4. Copy the formatted JSON or download it as formatted.json.

JSON syntax rules that catch people out

JSON (RFC 8259) is stricter than JavaScript object syntax. These are the errors the validator recognizes and explains:

InvalidValidRule
{"a": 1,}{"a": 1}No trailing commas
{'a': 'x'}{"a": "x"}Only double quotes
{a: 1}{"a": 1}Keys must be quoted strings
{"n": .5}{"n": 0.5}Numbers start with a digit or minus
{"n": 007}{"n": 7}No leading zeros
{"v": NaN}{"v": null}No NaN, Infinity or undefined
// note(remove it)No comments
a raw tab or line break in a string"a\tb", "a\nb"Control characters must be escaped

Other things the validator reports: a missing comma between two items, an unclosed string, a missing closing bracket, curly quotes pasted from a word processor, invalid escapes such as \x, and extra text after the end of the value. A document has exactly one top-level value, which may be an object, an array, a string, a number, true, false or null.

What the formatter does not change

Formatting changes only the whitespace between tokens. Spaces inside strings are kept, the order of array items is kept, and unless you choose Sort keys, the order of keys is kept too. Two things can change because of how JavaScript reads JSON: a repeated key keeps only its last value, and integers larger than 9,007,199,254,740,991 lose precision. The tool warns about the second case.

Worked examples

A trailing comma

Input {"a":1,} reports: Invalid JSON at line 1, column 8: Trailing comma: remove the comma before }. Column 8 is the closing brace that follows the comma.

A broken multi-line config

In {"a":1, followed by a second line "b":tru}, the error points to line 2, column 7, where the unquoted word tru starts. Only true, false and null may appear without quotes.

An ID that changes

{"id": 12345678901234567890} is valid, but the formatted output reads 12345678901234567000. The warning explains that the integer exceeded the safe range. This is why some APIs, Twitter's among them, also send large IDs as strings.

Tips and common mistakes

Limits and privacy

Input up to 10 MB is accepted. Extremely deep nesting, thousands of levels, may exceed the browser's limits and is reported as an error instead of freezing the page. The validator stops at the first error. Your JSON, including any tokens or personal data inside it, is processed in the browser and never sent anywhere.

Frequently asked questions

Why is my JSON invalid?

The most common causes are a comma after the last item, single quotes instead of double quotes, property names without quotes, comments, and values such as NaN or undefined. The validator names the problem and points to its line and column.

Are comments allowed in JSON?

No. The JSON standard (RFC 8259) has no comment syntax. Some tools accept JSONC or JSON5, which allow comments, but a standard parser rejects them.

Why did a large number change after formatting?

JavaScript stores numbers as 64-bit floating point, which holds integers exactly only up to 9,007,199,254,740,991. 12345678901234567890 becomes 12345678901234567000. Keep large IDs as strings.

What does Sort keys do?

It orders the keys of every object alphabetically at every level, which makes two JSON files easier to compare. Array order is never changed.

What happens to duplicate keys?

JSON.parse keeps the last value for a repeated key, so {"a":1,"a":2} becomes {"a":2}. The standard says names should be unique for this reason.

Does minifying change the data?

No. Minify removes only whitespace between tokens. Spaces inside strings are kept.

How big a file can I format?

Up to 10 MB. Very deep nesting, thousands of levels, can exceed the browser's limits and is reported as an error rather than freezing the page.

Is my JSON sent anywhere?

No. Parsing and formatting happen in your browser, which matters for API responses that contain tokens or personal data.