JSON Formatter — Format, Validate & View JSON Online

JSON Formatter

Paste JSON into the input pane and get it re-indented, sorted, minified or converted in the output pane. The formatter reads the input with the browser's built-in JSON.parse and writes it back with JSON.stringify, so the output is exactly what JavaScript sees. Each tab holds its own document. The formatting code runs in your browser and makes no network request with the input text.

How this tool handles JSON

  • Format runs JSON.stringify(JSON.parse(input), null, spaces). The indent selector offers 2, 3, 4 or 8 spaces. Output uses \n line endings and has no trailing newline.
  • Indent setting is stored in localStorage under json-indent-spaces and applies to every tab. It is not per tab.
  • Sort keys sorts object keys at every nesting level using JavaScript's default string order. Array order is kept. The result is then indented with the same setting.
  • Minify runs JSON.stringify(JSON.parse(input)). Spaces inside string values are kept.
  • Validate parses the input. Valid JSON that repeats a key in the same object is reported as valid with a duplicate-key warning that gives both line numbers.
  • Auto-correct formats input that already parses. Otherwise it passes the text to the jsonrepair library, which accepts comments, single quotes, unquoted keys, trailing commas and Python-style True.
  • Invalid input produces output that begins with a red cross mark and the text Invalid Json:, followed by the parser's message and its line and column. The editor moves the cursor to that position when it can.
  • Live mode lets a command re-run 800 ms after you stop typing. It is off until you turn it on for a command.

Tree View shows the output as a collapsible tree. You can expand or collapse all nodes, copy a value, or copy the path to a node. Ctrl/Cmd+E copies the output pane. Ctrl/Cmd+B collapses the Explorer side panel.

Worked example

A Kubernetes ConfigMap pasted as one line:

{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"api-config","labels":{"app":"api"}},"data":{"LOG_LEVEL":"info","PORT":"8080"},"immutable":false}

Format with 2 spaces produces:

{
  "apiVersion": "v1",
  "kind": "ConfigMap",
  "metadata": {
    "name": "api-config",
    "labels": {
      "app": "api"
    }
  },
  "data": {
    "LOG_LEVEL": "info",
    "PORT": "8080"
  },
  "immutable": false
}

Gotchas

Duplicate keys: the first value is lost. Validate reports this input as valid, with a warning:

{"status": "pending",
"status": "shipped"}

Format keeps only the last value, "status": "shipped". Fix the source so each key appears once.

Large integers lose digits. {"orderId": 12345678901234567890} formats as {"orderId": 12345678901234567000}. JSON numbers are read as 64-bit floats. Send IDs longer than 15 digits as strings.

Numbers are rewritten. 1.0 becomes 1, 1e3 becomes 1000, -0 becomes 0, and 1e400 becomes null, because the value overflows to infinity and JSON.stringify writes that as null.

Comments, trailing commas and NaN are errors. Validate rejects them, and the message points at the position. {"tags":[1,2,],} fails with Unexpected token ']'. Auto-correct removes the trailing commas and comments and returns valid JSON.

Auto-correct accepts text that is not JSON. not json at all comes back as the JSON string "not json at all". Check the output before you use it.

Escapes are rewritten. "\u0041\/" formats as "A/". The text is the same, but a diff against the original will show changes.

Frequently asked questions

Can I work on several JSON documents at once? Yes. Each tab holds its own document, and tabs are saved in browser storage on this device, so they are still there after a reload.

Does it check JSON against a JSON Schema? No. It checks syntax and reports duplicate keys. Use a schema validator for rules about structure and types.

Why does a very large file make the page slow? The parse and stringify calls run on the page's main thread. The formatter does not use Web Workers. For very large files, a command-line tool such as jq . file.json or python3 -m json.tool file.json avoids the browser limit.

How do I copy the formatted output? Press Ctrl/Cmd+E to copy the output pane to the clipboard.

Can I hide the side panel? Yes. Press Ctrl/Cmd+B to collapse the Explorer. The tool remembers that choice on this device.