JSON formatter — pretty-print, sort keys and pinpoint errors

Paste JSON and get it neatly indented, optionally with keys sorted A–Z, or an exact line and column for the first error if it is not valid JSON.

Live demo · real result from this tool

Formatted JSON

{  "id": 1024,  "name": "Asha Rao",  "roles": [    "admin",    "editor"  ],  "address": {    "city": "Pune",    "postcode": "411001"  },  "active": true}
Lines13
Size
165 B

Processed on your device — nothing is uploaded.

How to use the JSON formatter

  1. Paste your data into the JSON box (a sample is filled in).
  2. Choose an Indent: 2 spaces, 4 spaces, Tabs, or None (minified).
  3. Tick Sort keys A–Z if you want object keys in alphabetical order.
  4. Read the Formatted JSON, with its line count and size, or the error message and code frame.
  5. Copy the result or download it as formatted.json.

What it does and when to use it

JSON from an API, a log file or a database export usually arrives as one long line. The formatter breaks it into an indented tree so you can see which values belong to which object and how deep the nesting goes. Sorting keys is useful before comparing two versions of a config file, because the same data in a different order then lines up.

It also acts as a quick checker. Invalid JSON is not “fixed” behind your back: the tool stops at the first problem and tells you where it is, with a marker under the exact character.

To compare two JSON documents, use the JSON diff tool. If you need types for code, the JSON to TypeScript converter turns the same data into interfaces, and for broken JSON with comments or single quotes, the JSON repair tool can try to fix it.

How it works

The input is parsed with the browser’s built-in JSON.parse. If that succeeds, the tool optionally sorts keys recursively and prints the result with your chosen indent. If parsing fails, a strict scanner written for this site walks the text according to the JSON standard (RFC 8259) to find the first error and explain it in plain words, such as “Trailing comma” or “Missing comma between properties”. A byte-order mark at the start of a file is ignored. Everything happens on your device.

Worked examples

These outputs come from the formatter.

A compact object. {"a":1,"b":[1,2]} with a 2-space indent becomes:

{
  "a": 1,
  "b": [
    1,
    2
  ]
}

Sorted keys. {"b":2,"a":{"d":4,"c":3}} with Sort keys A–Z ticked puts a before b, and inside a, c before d.

Single quotes. {'name': 'Asha'} is not JSON. The tool reports: “Invalid JSON — line 1, column 2: Object keys must use double quotes, not single quotes.”

Limits and tips

  • Duplicate keys are kept only once (the last value wins), as in most JSON parsers. The validator lists them.
  • Comments are not allowed in standard JSON. Remove them, or use the repair tool.
  • Very large files of many megabytes may make the page slow, since everything runs in the browser tab.
  • Escaped Unicode such as é is printed as the character itself (é) after formatting, which is the same value.

Frequently asked questions

Why does my JSON fail to format?
Something in it is not valid JSON. The most common causes are a trailing comma after the last item, single quotes instead of double quotes, keys without quotes, comments, and values such as undefined or NaN. The error message names the problem and shows the line and column.
Does sorting keys change my data?
It changes only the order of keys inside objects, at every level. Arrays keep their order, because in an array the order is part of the data. Most programs that read JSON ignore key order, but check if yours relies on it.
Can I minify JSON here too?
Yes. Set Indent to "None (minified)" to get everything on one line. The JSON minifier does the same and also reports how many bytes you saved.
Will large numbers stay exact?
Not always. The formatter reads JSON with JavaScript, which stores numbers as 64-bit floating point, so integers beyond 2^53 (about 9 quadrillion) can be rounded. The JSON validator warns about such numbers.
Is my JSON uploaded?
No. It is parsed and formatted in your browser, so API responses with tokens or customer data stay on your device.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close