EthicalFusion

JSON Formatter

Format and beautify minified JSON with proper indentation.

Was this tool helpful?

Thanks for the feedback!

The JSON Formatter takes compact or messy JSON, such as an API response on one line, and re-prints it with two-space indentation so the structure is easy to follow. If the input is not valid JSON, you get the parser's error message with the position of the problem instead, so the formatter doubles as a quick syntax check.

Formatting an API response

This single line from an order API:

{"order":{"id":"ORD-1042","total":1499.00,"items":[{"sku":"TSHIRT-M","qty":2}]},"paid":true}

is printed as:

{
  "order": {
    "id": "ORD-1042",
    "total": 1499,
    "items": [
      {
        "sku": "TSHIRT-M",
        "qty": 2
      }
    ]
  },
  "paid": true
}

Look closely at total: 1499.00 became 1499. The formatter parses the JSON into JavaScript values and prints them again, so the data is identical but its written form can change.

Side effects of parsing and re-printing

  • Numbers are normalised. 1.50 becomes 1.5 and 1e3 becomes 1000.
  • Very large integers lose precision. JavaScript numbers are exact only up to 9,007,199,254,740,991. An ID like 12345678901234567890 is shown as 12345678901234567000. If your API uses 64-bit IDs, don't copy them from the formatted output.
  • Duplicate keys collapse. If an object contains the same key twice, only the last value remains.
  • Numeric-looking keys move first. Keys such as "2" and "1" are listed before other keys, in ascending order, because that is how JavaScript orders object properties.
  • Escapes are decoded. "caf\u00e9" is shown as "café".

Reading the error messages

Errors come from your browser's JSON parser, and Chrome and Edge include a line and column, for example "Expected double-quoted property name in JSON at position 7 (line 1 column 8)". The usual causes:

  • Trailing comma after the last item, as in {"a":1,}. JavaScript allows it; JSON doesn't.
  • Single quotes around keys or strings. JSON requires double quotes.
  • Unquoted keys like {name: "x"}, which is a JavaScript object literal, not JSON.
  • Comments. // and /* */ aren't part of JSON, even though some config files use them.
  • Truncated input, shown as "Unexpected end of JSON input", often because a log line or copied response was cut off.

When an integration fails, format the raw response first. It is often an HTML error page or an empty body rather than the JSON you expected, and the error message makes that obvious in seconds.

Related JSON tools

Parsing runs in your browser, which makes it reasonable for responses containing internal data, though redacting tokens before sharing formatted output is still a good habit. To compress JSON again, use the JSON Minifier; to generate TypeScript interfaces from the same sample, try JSON to TypeScript.

Frequently asked questions

Why did my large ID number change after formatting?
JavaScript can only represent integers exactly up to 9,007,199,254,740,991. Larger numbers are rounded, so keep such IDs as strings in your JSON.
Why does my JavaScript object fail to format?
JSON is stricter than JavaScript: keys and strings need double quotes, and trailing commas and comments are not allowed.
What indentation does the formatter use?
Two spaces per level, which is the most common style for JSON in APIs and code repositories.
Why did 1499.00 become 1499?
The JSON is parsed into numbers and printed again, and 1499.00 and 1499 are the same number. Keep prices as strings if the exact text matters.
Where is the error in my JSON?
The error message gives a character position, and Chrome and Edge also give the line and column. Check just before that point for a missing comma, quote or bracket.

Related tools

People also used

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.