Skip to content
PC Moment

Free tool

JSON Formatter and Validator

Paste JSON to pretty-print or minify it, sort the keys and find syntax errors by line and column. Everything runs in your browser.

A JSON formatter turns a dense, one-line API response or config file into indented text you can actually read, and tells you exactly where the syntax breaks when it doesn’t parse. This one also minifies JSON for sending over the wire and can sort keys so two files are easier to compare. It runs on your browser’s own JSON parser, so nothing you paste is uploaded.

How to use the JSON formatter

  1. Paste your JSON into the text box.
  2. Choose the indent: 2 spaces, 4 spaces or Tab.
  3. Tick Sort keys alphabetically if you want the keys of every object in A to Z order.
  4. Select Format to pretty-print the JSON, or Minify to strip all the whitespace.
  5. Read the status line: Valid JSON, or the parser’s error message with the line and column where it failed.
  6. Use Copy to put the result on your clipboard, or Download .json to save it as a file.

How it works

The tool parses your text with JSON.parse, the parser built into every browser, and writes it back out with JSON.stringify:

  • Format writes each value on its own line and indents every nesting level by the indent you chose.
  • Minify writes the same data with no whitespace at all. JSON allows spaces, tabs and line breaks only around its structural characters ({ } [ ] : ,), so removing them never changes the data (RFC 8259, section 2).
  • Sort keys reorders the keys of every object, at every level, before the output is written. Arrays keep their order, because in an array the order is part of the data.

Because the browser’s parser does the work, the rules are exactly the JSON standard, with two behaviors worth knowing:

  • Big numbers lose precision. JavaScript stores every JSON number as a 64-bit float, which represents whole numbers exactly only between −(2^53 − 1) and 2^53 − 1, that is up to 9,007,199,254,740,991. RFC 8259 calls this the range where implementations agree. A longer integer is rounded to the nearest number a float can hold.
  • Duplicate keys keep the last value. RFC 8259 says object names “SHOULD be unique” and that software behaves unpredictably when they aren’t. The ECMAScript specification settles it for JavaScript: earlier values for the same key are overwritten.

Note: The wording of the error message comes from your browser, so it differs between Chrome, Firefox and Safari. When a browser reports only a character position, the tool works out the line and column for you.

Worked examples

Format a minified API response (2 spaces). This input:

{"name":"Ada","languages":["en","fr"],"active":true,"id":7}

becomes:

{
  "name": "Ada",
  "languages": [
    "en",
    "fr"
  ],
  "active": true,
  "id": 7
}

With Sort keys alphabetically ticked, the same object comes out in the order active, id, languages, name, and the array still reads "en", "fr".

Find a trailing comma. This JSON fails because of the comma after 36:

{
  "name": "Ada",
  "age": 36,
}

The parser expects another property name after a comma and finds } instead, so it reports an error at line 4, column 1. Delete the comma and it validates.

A 64-bit ID that changes. {"id": 12345678901234567890} is valid JSON, but after parsing in JavaScript the number becomes 12345678901234567000, because it is far above 2^53 − 1. If an API sends IDs that large, it should send them as strings ("id": "12345678901234567890"), which the formatter keeps exactly.

Common JSON errors

ErrorInvalidValid
Trailing comma[1, 2, 3,][1, 2, 3]
Single quotes{'name': 'Ada'}{"name": "Ada"}
Unquoted key{name: "Ada"}{"name": "Ada"}
Comment{"a": 1} // note{"a": 1}
Undefined value{"a": undefined}{"a": null}

Trailing commas and single quotes are rejected by JSON.parse, as MDN’s reference notes. Comments and undefined are JavaScript, not JSON: the JSON grammar in RFC 8259 has no comment syntax, and its only literal names are true, false and null.

Frequently asked questions

Is my JSON sent to a server?

No. The formatter uses your browser's built-in JSON.parse and JSON.stringify, so the text you paste never leaves your device.

Why does my JSON say it's invalid?

The most common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted property names and comments, none of which the JSON grammar allows. The error message shows the line and column where the parser stopped.

Why did a long number change after formatting?

JavaScript stores JSON numbers as double-precision floats, which hold whole numbers exactly only up to 2^53 − 1 (9,007,199,254,740,991). Larger numbers, such as 64-bit IDs, are rounded; send them as strings if every digit matters.

What happens to duplicate keys?

The last value wins. JSON.parse keeps only the final value for a repeated key, so formatting or minifying removes the earlier ones. The JSON standard says names should be unique for this reason.

Does sorting the keys change my data?

No. Sorting only changes the order of the keys inside each object; values and array order stay the same. JSON objects are unordered by definition, although some programs and diffs care about the order.

Related guides

Free Developer and PC Tools

Free formatters, decoders and converters for developers and PC users. Everything runs in your browser, and nothing you type is sent anywhere.

2 min read