JSON Formatter

Indent and beautify JSON, with syntax error locations when available.

Input
JSON input
Output
Result
Options

Spaces per level of nesting.

Further reading

  • How to format JSONA practical guide to formatting JSON: fixing syntax errors from the line and column, choosing indentation, sorting keys, and what formatting cannot change.

About this tool


Minified JSON is efficient for machines and unreadable for people. This formatter re-indents a JSON document so its structure is visible: one key per line, nesting expressed as indentation, and arrays laid out so you can count their elements.

It also checks JSON syntax using JSON.parse. Invalid input is rejected rather than repaired. When the parser supplies a position, you get the line and column of the problem plus a pointer at the offending character; some errors have a message without a location.

How to use it

  1. Paste or upload your JSONDrop a .json file onto the input pane, use the file picker, or paste text directly.
  2. Choose an indent widthTwo spaces is the default. Open Options to switch to four spaces or tabs.
  3. FormatPress the Format button, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Review any errorIf the document is invalid, read the error message and use the line and column when available to locate the problem.
  5. Copy or downloadCopy the result to your clipboard, or download it as a .json file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Minified input expanded

Input

{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true,"score":null}

Output

{
  "id": 42,
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  },
  "active": true,
  "score": null
}

Nesting becomes visible, and every scalar type is preserved exactly.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

What formatting changes, and what it does not
Formatting parses and re-serialises the document rather than changing whitespace alone. Keys that are valid JavaScript array indices are emitted in numeric order; other keys normally keep their input order unless you enable key sorting. String escapes may be rewritten. Numbers are re-emitted from their parsed value, so 1.0 becomes 1 and 1e3 becomes 1000: the values are equal, but the text differs.
Duplicate keys
JSON permits duplicate keys, and JSON.parse keeps only the last one. A document containing {"a":1,"a":2} formats to {"a": 2} with the first value silently dropped. The JSON Validator can flag duplicates, but its heuristic scan is not reliable for keys containing escape sequences.
Large numbers lose precision
This tool parses numbers as JavaScript IEEE 754 doubles. Not every integer beyond 2^53 is exactly representable: 9007199254740993 becomes 9007199254740992. High-precision decimals can also be rounded, and numbers outside the finite range are serialised as null. If your data contains 64-bit IDs or high-precision decimals, transmit them as strings.

Limitations


  • Comments and trailing commas are rejected, because they are not valid JSON.
  • JavaScript IEEE 754 number parsing can round large integers and high-precision decimals. Numbers outside the finite range become null when serialised as JSON; this is not a restriction of JSON syntax itself.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Is my JSON uploaded anywhere?
No. Formatting runs in JavaScript on this page. You can verify it by opening the Network tab in devtools and formatting a document, no request carries your JSON input or formatted output.
Why did my number change?
Numbers are re-serialised from their parsed value, so 1.0 becomes 1 and 1e3 becomes 1000. Beyond the safe-integer limit of 9,007,199,254,740,991, not every integer is exactly representable by JavaScript IEEE 754 doubles. Numbers outside the finite range become null on output. Use strings for large IDs.
Can it fix invalid JSON automatically?
No, and deliberately so. Guessing at intent risks changing your data. The tool reports a syntax error and includes a location when available, so you can make the correction yourself.
Does it handle JSON with comments (JSONC)?
No. Comments are not valid JSON, so the parser rejects them. Strip comments first if you are working with a tsconfig.json or similar.