FilesCalcs

JSON formatter and validator

Paste or upload JSON to tidy it, check it, or squash it onto one line. Errors show the line and column so you can fix them fast.

Worked out in your browser. Nothing is sent anywhere.

How to use the JSON formatter

  1. Paste your JSON into the box, or upload a .json file.
  2. Choose 2 spaces, 4 spaces or tabs, and tick sort keys if you want them in order.
  3. Press format to tidy it or minify to remove whitespace.
  4. Fix any error at the line and column shown, then copy or download the result.

Common reasons JSON fails to validate

JSON is stricter than the JavaScript it looks like. Most errors come from a short list:

  • A trailing comma after the last item, as in {"a": 1,}
  • Single quotes instead of double quotes around keys or strings
  • Keys without quotes, as in {name: "Sam"}
  • Comments, which JSON does not allow
  • Unescaped line breaks or double quotes inside a string
  • Special values such as undefined or NaN, which are not valid JSON

The line and column in the error usually point at, or just after, the problem. A missing comma or bracket is often reported on the next line, so look one line up if the flagged spot looks fine.

Format, minify or sort keys

Formatting adds line breaks and indentation so you can read nested data. Two spaces is the most common style in web projects, and four spaces or tabs suit people who prefer wider indents. Minifying does the opposite, removing all optional whitespace so the file is as small as possible for sending or storing.

Sorting keys puts the keys in each object in alphabetical order. The data means the same thing, since JSON objects are unordered, but sorted output makes it far easier to compare two versions of a config file or API response line by line.

Safe for API responses and config files

JSON often contains things you would not want to paste into a random website, such as tokens, customer records or internal settings. Here the formatting and validation run in your browser and nothing is uploaded, so the data does not leave your device.

Questions people ask

Does formatting change my data?

No. Formatting and minifying only change whitespace between values. Sorting keys changes their order, which does not change the meaning of a JSON object.

Can JSON have comments?

Standard JSON does not allow comments. Some tools accept variants such as JSONC or JSON5, but a strict validator will reject them.

Why is a trailing comma an error?

The JSON standard does not allow a comma after the last item in an object or array, even though JavaScript does. Remove it and the file will validate.

What is the difference between JSON and a JavaScript object?

JSON is a text format with stricter rules: keys and strings must use double quotes, and functions, comments and undefined are not allowed.