Skip to content

JSON.parse, then stringify with an indent

Format and check JSON

JSON is a data format with strict commas, quotes, and no comments. This page parses what you paste and prints it again with an indent, or on one line.

The parser is JSON.parse, so trailing commas, single quotes, and comments fail. The message from the engine is shown when the text is not JSON. Pretty print uses two spaces. Minify uses no extra space. Sort keys reorders every object by key name, at every nesting level, and leaves arrays in their original order. Numbers stay as JSON numbers. A very large integer can lose precision because JavaScript parses JSON numbers as IEEE values. Put such an id in a string if the exact digits matter.

The document stays in this tab. It is not sent to a formatter on a server.

This tool runs in your browser. Turn on JavaScript to use it.

Key order is not part of the data until you sort

Both objects are the same data. Sorting makes the bytes easier to diff.

Input
{"b":1,"a":[2,1]}
Pretty
{ "b": 1, "a": [ 2, 1 ] }
Keys sorted
{ "a": [ 2, 1 ], "b": 1 }

How to use it

  1. 1Paste a JSON value: an object, an array, or even a single string.
  2. 2Format to read it, minify to ship it, or sort keys before a diff.
  3. 3If the parser complains, fix the spot it names. The page will not guess a repair.

Good to know

  • JSON5, comments, and trailing commas are out of scope.
  • Object key order in the input is preserved until you ask to sort.
  • Undefined and functions cannot appear in JSON. A previous JavaScript value is not accepted, only text.

Questions

Will this fix broken JSON?

No. It reports the parse error. Adding the missing comma is left to you.

Why did a long id change?

JSON numbers are floating point in this browser. Keep a long identifier in quotes.

Does sort keys change arrays?

No. [2, 1] stays [2, 1]. Only object keys move.

Related tools

  • Convert JSON and YAML

    YAML is easier to scan than a one-line JSON object, and JSON is what most programs parse. This page converts between them for a plain subset.

  • Convert CSV and JSON

    CSV is a table in text. This page parses quotes and doubled quotes, then prints JSON, or walks a JSON array and prints CSV.

  • Parse and build a query string

    A query string is a list of pairs, not one encoded blob. This page splits q=red&size=42 into rows you can edit, then joins them back.