Skip to content
AgileLogics

JSON Formatter

Paste any JSON document and format it with consistent 2-space indentation, making it easy to read and debug. Invalid JSON is flagged with the exact parse error.

How it works

Paste your JSON into the input panel and click Format. The formatted result appears in the output panel, ready to copy.

What is a JSON formatter?

A JSON formatter takes JSON text, such as a minified API response or a hand-edited config file, and rewrites it with consistent line breaks and indentation so its structure is easy to read. This one also checks the syntax as it goes: if the input isn't valid JSON, you get the parser's error message instead of output.

JSON (JavaScript Object Notation) is the standard data format for web APIs and many configuration files. It's defined in RFC 8259 and ECMA-404. Servers usually send it minified, with every space and newline stripped to save bandwidth, which makes it hard to read when debugging.

How to format JSON

  1. Paste your JSON into the input box. It can be minified, unevenly indented, or copied from a log.
  2. Click Format.
  3. Copy the formatted result from the output panel.

For example, this minified response:

{"user":{"id":42,"name":"Ada Lovelace","roles":["admin","editor"],"active":true}}

becomes:

{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "roles": [
      "admin",
      "editor"
    ],
    "active": true
  }
}

Common JSON errors and how to fix them

Most invalid JSON comes from a handful of mistakes, usually from writing JSON by hand or copying a JavaScript object literal:

Input Error you'll see Fix
{"name": "Ada",} Expected double-quoted property name Remove the trailing comma after the last item
{name: "Ada"} Expected property name or '}' Put keys in double quotes: "name"
{"name": 'Ada'} Unexpected token ''' Use double quotes for strings, never single quotes
{"a": 1} // note Unexpected non-whitespace character after JSON Remove comments; JSON doesn't allow them
{"a": undefined} Unexpected token Use null; undefined, NaN and Infinity aren't valid JSON

The exact wording depends on your browser. Chrome and Edge include the line and column of the error, which is usually the fastest way to find it.

What changes when JSON is formatted

Formatting is meant to change only whitespace, but because the input is parsed and re-serialized, a few things can differ from what you pasted. These are worth knowing before you paste the result back into a file:

  • Duplicate keys collapse to the last one. {"id": 1, "id": 2} becomes {"id": 2}.
  • Very large integers lose precision. Anything above 9,007,199,254,740,991 (2^53 - 1) is rounded, so 12345678901234567890 becomes 12345678901234567000. Twitter's API, for example, returns tweet IDs as strings for exactly this reason.
  • Integer-like keys move to the front. In {"b": 1, "2": "two", "1": "one"}, the keys "1" and "2" are printed first. Other keys keep their original order.
  • Numbers are normalized. 1.50 becomes 1.5 and 1e3 becomes 1000. The values are equal, but the text differs.
  • Unicode escapes are decoded. "é" is printed as "é".

None of these change what the data means to a program that reads it, with the exception of large integers. If you need a byte-for-byte copy of the original structure, compare the two with the code diff tool.

Formatting vs. validating vs. minifying

  • Formatting (this tool) adds indentation for people to read.
  • Validating only answers "is this valid JSON?", without changing anything. It checks syntax, not whether the data matches a particular JSON Schema.
  • Minifying does the reverse of formatting: it strips all optional whitespace to make the payload as small as possible.

If you want to edit JSON with syntax highlighting rather than just reformat it, use the online JSON editor, which also has a one-click Format button.

Last updated

Frequently asked questions

Does my JSON get sent to a server?
No. Formatting happens entirely in your browser using its built-in JSON parser, so the data you paste never leaves your device. You can even disconnect from the internet after the page loads and the formatter keeps working.
What happens if my JSON is invalid?
The formatter shows the parser's error message instead of output, usually with the line and column of the first problem, for example "Expected double-quoted property name in JSON at position 14 (line 1 column 15)". Fix that spot and format again.
Why did one of my keys disappear after formatting?
Your input probably had the same key twice in one object. The JSON specification doesn't forbid duplicates, but JavaScript keeps only the last value, so {"id":1,"id":2} formats as {"id":2}. If keys go missing, search your input for duplicates.
Why did a large number change after formatting?
Numbers are parsed as 64-bit floating point, which is exact only up to 9,007,199,254,740,991 (2^53 - 1). A longer integer such as 12345678901234567890 comes back as 12345678901234567000. Store IDs that large as strings if you need them exact.
Can it format JSON with comments or trailing commas?
No. Comments and trailing commas are valid in JSON5 and JSONC (used by some config files, such as VS Code settings) but not in standard JSON, so the formatter reports them as errors. Remove them first.
What indentation does it use?
Two spaces per nesting level, which is the most common convention in JavaScript projects and API documentation.