JSON Formatter

Paste or upload JSON to format, indent and check it. Runs in your browser.

Pasted text and chosen files stay on this device. Nothing is sent to a server.

Drop a file here, choose one, or paste.

No output yet Format to see the result here.

How to use it

  1. 1

    Paste the text into the input.

  2. 2

    Choose an indent if the default is not what your file uses.

  3. 3

    If it comes back unformatted with an error, the error names the line and column where parsing stopped.

What it does

A formatter does one thing: it takes JSON text and gives the same data back with the structure visible. The interesting part is not the indentation, it is what happens when the input is not JSON at all — a formatter that reformats it anyway has told you nothing.

Parse the input, re-serialise with the chosen indent, and return the text. If parsing fails, return the parser error with its position instead of output.

Why it works this way

Formatting cannot change what the data is — only how it is laid out. That is why a formatter is a safe place to paste something: if it comes back, it parsed.

A formatter that returns output for input that is not valid JSON is worse than one that errors, because the output looks like an answer.

Sorting keys changes the order of an object's members, which JSON does not consider significant. It makes two documents diffable by eye; it does not make them equal.

Examples

{"a":1,"b":[2,3]}
{
  "a": 1,
  "b": [
    2,
    3
  ]
}
the shape becomes visible: two members, one of them a list of two
{"a":1,}
error at line 1 column 8: unexpected }
a trailing comma is not JSON, and the error says where

Inputs and outputs

  • JSON text
  • indent width (2, 4, or tab)
  • sort keys: on/off
  • the formatted JSON text
  • or the parse error, with line and column

Edge cases

  • already indented — output is stable, not doubled
  • empty string — error, not empty output
  • very large input — indentation is not the bottleneck, parsing is
  • BOM and leading whitespace

Frequently asked questions

Does formatting change my data?

No. Member order may change if you sort keys; values and structure do not.

Why did it reject JSON my other tool accepted?

Tools differ on trailing commas, comments and single quotes. None of those are JSON, so this one rejects them and names the position.

Related tools

Sources

  • RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format