JSON Formatter

Format, beautify, validate and minify JSON online. Shows the line and column of syntax errors. Free and private: it runs in your browser.

How to format, validate and minify JSON

  1. Paste your JSON into the top box. It is checked as you type, and the status line turns green or red.
  2. Click Format to pretty-print it with 2 spaces, 4 spaces or tabs, or Minify to remove every unnecessary space and line break. Tick Sort keys A→Z to put object keys in order.
  3. Copy the result or download it as data.json. Example loads a small sample if you just want to see how it works.

For valid input the status line describes what you pasted, for example Valid JSON · object with 7 keys · 221 characters. That figure is the sample formatted with 2 spaces; minified, the same data is 159 characters, and with 4 spaces it is 259. Formatting and minifying only change whitespace between values, so the data itself stays the same.

Fixing errors

If the JSON is invalid, the status line shows the parser's error message with the line and column where it gave up. Clicking Format or Minify also moves the cursor to that spot in the input. The exact wording comes from your browser, so it differs between Chrome, Firefox and Safari. The usual culprits:

MistakeExampleFix
Trailing comma{"a":1,}Delete the comma after the last item
Single quotes{'name': 'Alice'}Use double quotes for keys and strings
Unquoted key{name: "Alice"}Quote every key: "name"
Comment{"a": 1 /* note */}Remove comments; standard JSON has none
Missing comma{"a": 1 "b": 2}Add a comma between items
Unclosed bracket[1, 2, 3Add the closing ] or }
Leading zero{"a": 007}Write 7, or use a string "007"
Non-JSON valuesNaN, undefined, True, NoneUse null, true or false
Raw line break in a stringa string typed across two linesWrite the line break as \n
Several documents{"a":1} then {"a":2} on the next lineWrap them in [ ] separated by commas

The True/None row is the typical sign of a Python dictionary that was printed rather than converted with json.dumps(), and the last row is the JSON Lines format used by many log files, where each line is a separate document.

What counts as valid JSON

JSON is defined by RFC 8259 and the ECMA-404 standard. A JSON text is a single value: an object in { }, an array in [ ], a string in double quotes, a number, or one of true, false and null. That means 42 or "hello" on its own is valid JSON too. The validator here is strict and follows the standard, so relaxed formats like JSON5 or the “JSON with comments” used by some editor settings files will be rejected.

Things that can change when you format

The tool reads your JSON into JavaScript values and writes it out again, so a few details are normalised along the way:

  • Numbers are rewritten in their shortest form: 1.0 becomes 1, 1.50 becomes 1.5 and 1e3 becomes 1000. Integers beyond 9,007,199,254,740,991 lose precision – 12345678901234567890 comes out as 12345678901234567000 – and a number too large to represent, such as 1e400, becomes null.
  • Escapes are simplified: "café" becomes "café" and \/ becomes /. Control characters such as tabs stay escaped.
  • Duplicate keys collapse to one, and the last value wins: {"a":1,"b":2,"a":3} becomes {"a":3,"b":2}.
  • Keys that look like whole numbers move to the front in numeric order: {"b":1,"2":"two","a":3,"10":"ten"} becomes {"2":"two","10":"ten","b":1,"a":3}. This is how JavaScript orders object properties.

Apart from the large-number and duplicate-key cases, none of this changes the meaning of the data: the standard defines object members as unordered, and both spellings of a number or string are equivalent. If your IDs are that large, store them as strings.

Sorting keys

Sort keys A→Z orders the keys of every object at every level; arrays keep their order, because the order of array items is meaningful. Keys are compared by character code, so capitals come before an underscore and both come before lowercase letters: Zip, _id, age, name. Sorted keys make it much easier to compare two API responses or configuration files in the Diff Checker.

FAQ

Is my JSON sent to a server?

No. It is parsed and formatted by your browser, so API responses, tokens and customer records you paste here never leave your computer.

Can it repair broken JSON automatically?

No. Guessing a fix could silently change your data, so the tool only shows where the problem is and leaves the correction to you.

Does it check my data against a schema?

No. It checks syntax only – whether the text is well-formed JSON – not whether particular keys or types are present.

What related tools are there?

To turn JSON into a spreadsheet-friendly table, use the CSV ⇄ JSON Converter. To read the JSON inside a login token, use the JWT Decoder, and for Base64-encoded payloads, Base64 Encode / Decode.