Skip to content
MagicWebBox
Sign in

JSON formatter

Indent, minify and validate JSON, with the exact location of errors

Source code

Result

Paste JSON on the left, then click “Format”.

About this tool

The JSON formatter cleans up an API response, a config file or a minified export squeezed onto a single line. Paste the text, pick an indentation of 2 or 4 spaces, a tab, or the minified version, and run the formatter. The result appears next to the input, ready to copy or to download as a data.json file.

If the JSON is invalid, the tool shows the line and column of the first error and prints the offending line with a marker under the problem character. The sort option orders object keys alphabetically at every level, which makes two documents easier to compare. Changing the indentation or the sort option updates a result that is already displayed.

How to use it

  1. Paste your JSON into the Source code box.
  2. Pick an Indentation: 2 spaces, 4 spaces, Tab or Minified.
  3. Check “Sort keys” if you want properties in alphabetical order.
  4. Click “Format”.
  5. Grab the result with “Copy” or “Download”.

Frequently asked questions

How does the tool find the location of a syntax error?

When the JSON cannot be parsed, a small parser walks through the text using the same rules as JSON.parse and stops at the first invalid character. The tool shows its line and column, then the offending line with a caret under the error.

Are comments and trailing commas allowed?

No. The tool follows the strict JSON syntax of JSON.parse: comments, trailing commas, single quotes and unquoted keys all trigger an error with its position. Remove them before formatting a JSONC or JSON5 file.

Does sorting keys change arrays?

No. Only object keys are sorted, at every depth, including objects nested inside arrays, with uppercase letters before lowercase ones. The order of items within an array is always preserved.

Is my JSON sent to a server?

No. The text is parsed and formatted by your browser with JSON.parse and JSON.stringify, with no network request. Only your indentation and sort settings are saved locally; the JSON you paste is not stored.