Skip to content
LocalOnly

Online JSON Formatter & Validator

Stable

Pretty-print JSON with configurable indentation and instant validation.

Everything is processed locally in your browser

About Online JSON Formatter & Validator

The JSON Formatter is a free online tool that turns compact, minified, or hand-edited JSON into clean, properly indented output that is easy to read and review. It doubles as a JSON validator: paste or upload a file, pick your indentation style, and it pretty-prints valid JSON while pinpointing the exact line and column of any syntax error. Copy the result, download it as a .json file, and keep working offline. Everything is parsed and rendered locally in your browser, so even large or confidential payloads never leave your machine.

Features

  • Configurable indentation: 2 spaces, 4 spaces, or tabs
  • Instant validation with the exact line and column of any syntax error
  • Upload a .json file or drag and drop it, and download the formatted result
  • Handles multi-megabyte documents without freezing the UI
  • Preserves Unicode characters and does not re-encode escape sequences
  • One-click copy of the formatted result to your clipboard
  • Works fully offline once loaded - nothing is uploaded to a server

How to use Online JSON Formatter & Validator

  1. 1

    Paste your JSON

    Drop raw, minified, or messy JSON into the input editor. It can be a single object, an array, or any valid JSON value.

  2. 2

    Choose indentation

    Select 2 spaces, 4 spaces, or tabs to match your project's style guide.

  3. 3

    Format

    The tool pretty-prints the document instantly and flags any syntax errors with their location.

  4. 4

    Copy the result

    Copy the clean output to your clipboard or download it as a .json file.

Examples

Minified input to formatted output

A compact object expanded to two-space indentation.

Input

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

Output

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

How JSON formatting and validation work

Formatting is a parse-and-re-serialize round trip

A formatter does not insert line breaks into your text with a regular expression. It parses the document into an in-memory value - objects, arrays, strings, numbers, booleans and null - and then writes that value back out with an indentation setting. That round trip is why formatting is reliable: if the parse succeeds, the output is guaranteed to be valid JSON, because it was produced by a serializer rather than by string surgery.

It also explains the one surprise people hit. Because the text is rebuilt from parsed values rather than edited in place, anything that was not part of the data model disappears. Comments are gone. Original number spelling is gone. The gap between `{ "a":1 }` and `{"a" : 1}` is gone, because both parse to the same value. What survives is exactly the data, and nothing about how it happened to be typed.

What is preserved, and what is quietly normalised

Key order is preserved. JSON objects are unordered by specification, but every mainstream parser keeps insertion order, and this formatter does too - so a formatted file diffs cleanly against its source. If you want alphabetical order instead, that is a deliberate, separate operation.

Numbers are normalised to their shortest round-trip representation. `1.0` becomes `1`, `1e3` becomes `1000`, and `-0` becomes `0`. The numeric value is identical; only the spelling changes. This matters if you are diffing formatted output against a file that used a different numeric style, because those lines will show as changed even though nothing semantically moved.

Strings keep their characters but may change their escaping. A literal emoji stays an emoji rather than being converted to a `\u` escape sequence, and an existing `\u0041` escape is resolved to `A`. Both forms mean the same string; the formatter emits the readable one and escapes only what JSON requires - quotes, backslashes and control characters.

Why the formatter is also a validator

You cannot serialise a document you failed to parse, so every format attempt is implicitly a validation pass. When the parse fails, the underlying error carries a character offset into the source text. Converting that offset into a line and column is what turns an unhelpful "Unexpected token" into a cursor position you can jump to.

This is worth knowing because it sets expectations about error reporting. A JSON parser stops at the first problem - it does not collect a list of every error in the file. Fix the reported position, run it again, and the next problem surfaces. On a badly mangled document that can mean several passes, which is normal rather than a sign the tool is struggling.

Working with large documents

Formatting is memory-bound rather than CPU-bound. A parsed JSON document typically occupies several times the size of its text form, because every string, array and object becomes a separate heap allocation. A 50 MB file can therefore need a few hundred megabytes of working memory once parsed, and the formatted output adds indentation on top of that.

In practice, multi-megabyte documents format comfortably in a modern desktop browser. Tabs on memory-constrained devices, and files in the hundreds of megabytes, are where you should expect trouble - and the honest answer there is a streaming command-line tool like `jq`, which never holds the whole document in memory at once.

Reference

What a JSON parser normalises

Formatting rebuilds the document from parsed values, so these input forms all change on the way out - without changing meaning.

InputFormatted outputWhy
1.01Trailing zeros carry no numeric value
1e31000Exponent notation is expanded on output
-00Negative zero serialises as plain zero
"\u0041""A"Escapes resolve to the character they denote
{"a":1,"a":2}{"a": 2}Duplicate keys collapse; the last one wins
// comment(removed)Comments are not part of JSON

Which tool should you use?

These tasks overlap. Here is how to pick the right one for what you are actually doing.

You want readable JSON and an error report in one step
Stay here. The formatter validates as it parses, so a successful format is proof the document is well-formed, and a failure gives you the exact line and column.
You only need a yes-or-no answer on validity
The JSON Validator is the more direct tool. It reports structural problems without producing formatted output you do not need.
You need to explore a large, deeply nested document
Formatting a 10,000-line file gives you 10,000 lines to scroll. The JSON Tree Viewer lets you collapse branches and drill into the part you care about.
You are preparing JSON for transport or storage
Use the JSON Minifier instead. Formatting is for humans; minifying strips the whitespace back out for machines.
Your JSON needs to diff cleanly against another document
Format both, then sort keys with the JSON Sort Keys tool. Consistent ordering plus consistent indentation removes almost all diff noise.

Use cases

  • Reading an API response that arrived as a single minified line
  • Cleaning up JSON copied from logs before pasting it into a ticket
  • Standardizing indentation across config files in a repository
  • Reviewing a webhook payload during debugging
  • Preparing readable JSON snippets for documentation

Troubleshooting common errors

"Unexpected token } in JSON" pointing at the end of a block

Why: A trailing comma after the last element of an object or array. JavaScript object literals allow this; JSON does not.

Fix: Delete the comma before the closing brace or bracket. If the JSON came from a JavaScript file or a config format like JSONC, expect several of these.

"Unexpected token '" on a line that looks correct

Why: Single-quoted strings or unquoted keys. JSON requires double quotes on both keys and string values.

Fix: Convert `{name: 'Ada'}` to `{"name": "Ada"}`. Content copied from Python dictionaries or JavaScript literals almost always needs this.

"Unexpected token N" or an error on a numeric field

Why: `NaN`, `Infinity` or `-Infinity` in the document. These are valid JavaScript numbers but have no JSON representation.

Fix: Replace them with `null`, or with a string like `"NaN"` if the consumer can interpret it. The producer of the file is where this should really be fixed.

An error reported at line 1, column 1 on a file that opens fine elsewhere

Why: A byte order mark or other invisible character before the opening brace, usually from a Windows editor or an export.

Fix: Re-save the file as UTF-8 without BOM, or delete everything before the first `{` or `[` after pasting.

Comments vanish from the output

Why: The document is JSONC or JSON5, not JSON. Comments are stripped because they have nowhere to live in the parsed value.

Fix: Keep the commented original as your source of truth and treat the formatted output as a build artefact. `tsconfig.json` and `.vscode/settings.json` both fall into this category.

A long numeric ID comes back with different digits

Why: Integers beyond 2^53 cannot be represented exactly as IEEE-754 doubles, so they are rounded on parse. Snowflake IDs and some database keys hit this.

Fix: Have the producer emit large identifiers as strings. Once precision is lost in the parse, no formatter can recover it.

Limitations

What this tool deliberately does not do, so you know when to reach for something else.

  • Comments are removed, because JSON has no comment syntax. For JSONC or JSON5 files, keep the annotated original.
  • Duplicate keys collapse to the last occurrence, matching standard parser behaviour. If you need to detect duplicates, that has to happen before parsing.
  • Integers larger than 2^53 lose precision on parse. Emit them as strings upstream if exactness matters.
  • Only one syntax error is reported per pass, because parsing stops at the first failure.
  • Key order is left exactly as-is. Use the JSON Sort Keys tool if you want alphabetical ordering.

Frequently asked questions

Learn more

Command Palette

Search for a tool or command