Skip to content
Tools

JSON Formatter & Validator

A free online JSON formatter that lets you beautify, validate, minify and inspect JSON instantly. Everything runs locally in your browser for maximum privacy and performance.

Visible pane

Input

0 chars

Loading editor…

Waiting for input

What is a JSON formatter?

JSON — JavaScript Object Notation — is the format most software uses to exchange structured data. It is deliberately simple: objects, arrays, strings, numbers, booleans and null, and nothing else. That simplicity is why almost every API, configuration file and log pipeline speaks it.

A JSON formatter takes that data in whatever shape it arrives — minified onto a single line, indented three different ways, or copied out of a terminal — and rewrites it with consistent indentation and one value per line. The result is the same data, laid out so a person can read it.

This works because whitespace between JSON tokens carries no meaning. A parser treats these two documents as identical, so a formatter can move freely between them without ever changing what the data says:

Minified — 61 bytes
{"id":1,"tags":["api","json"],"owner":{"name":"Ada","active":true}}
Formatted — identical data
{  "id": 1,  "tags": ["api", "json"],  "owner": {    "name": "Ada",    "active": true  }}

Most formatters double as validators, because a document has to be parsed before it can be re-printed. If parsing fails, there is no formatted output to show — only an error, which is exactly the information you needed.

Why use a JSON formatter?

Machines are happy with a single 400 KB line. People are not. Formatting is what turns an opaque blob into something you can reason about, and it pays for itself in a few common situations:

  • Reading an API response. Most APIs return minified JSON to save bandwidth. Formatting reveals the shape of the response — which fields are nested, which are arrays, which came back null.
  • Finding the break in a payload. When a request is rejected as malformed, a validator points at the exact line and column instead of leaving you to count brackets.
  • Producing a readable diff. Two minified documents differ on line one and nowhere else, which tells you nothing. Format both — optionally with keys sorted — and a diff shows precisely which values moved, or hand the two documents to the JSON diff and let it line them up for you.
  • Reviewing configuration. Config files get read far more often than they get written. Consistent indentation makes an unfamiliar file approachable.
  • Shrinking a payload before shipping. The reverse operation matters too: minifying strips every optional byte before data goes over the wire or into storage, and reports how many bytes that saved.

Features

Everything below runs in your browser. There is no upload step, no queue and no account.

Beautify and minify

Beautify re-prints the document with your chosen indentation — two spaces, four spaces or tabs — putting each property and array item on its own line. Minify does the opposite, removing every optional space and newline to produce the smallest valid representation. Both run against the parsed data, not the raw text, so the output is guaranteed to be well-formed.

Live validation with exact positions

The document is validated as you type. Invalid JSON is underlined in the editor, and the status bar names the problem in plain language along with its line and column — plus a button that jumps the cursor straight to it.

Interactive tree view

The tree tab turns the document into a collapsible outline — the same view the dedicated JSON viewer is built around. Expand and collapse individual branches, jump to a level, or expand everything at once. Searching filters the tree to matching keys, matching values, or both, keeping the ancestors of each match so results stay in context. Every row can copy its key, its value or its JSON path.

Statistics

Character and line counts, how many objects, arrays and keys the document contains, how deeply it nests, and the byte size of the input, the formatted output and the minified output — so the saving from minifying is a number rather than a guess.

Sorting, escaping and clean-up

Optional transforms that change the document rather than just its layout: sort every object’s keys alphabetically for stable diffs, escape non-ASCII characters as \uXXXX for systems that expect pure ASCII, and drop properties that are null or empty. Each one is off by default and clearly labelled, because they alter your data.

A real editor

Line numbers, syntax highlighting, code folding, bracket matching, undo and redo, and find-and-replace. Only the visible lines are rendered, so a multi-megabyte document scrolls as smoothly as a short one.

Files, clipboard and print

Upload a .jsonfile or drop one anywhere on the editor. Copy the output, download it formatted or minified, or print it. Files are read with the browser’s own FileReader — they are never transmitted.

Duplicate key detection

Duplicate keys are legal to write but silently lossy: every parser keeps the last one. Rather than let that pass unnoticed, each duplicate is reported with its path and line so you can decide what was meant.

How to format JSON

  1. 1. Add your JSON. Paste it into the input panel, drag a .json file onto the page, or use the upload button. The example document is loaded to begin with — replace it or clear the editor.
  2. 2. Check the status bar. It reads Valid JSON as soon as the document parses. If it reads Invalid JSON, the message underneath names the problem and its position; use the line and column button to jump there.
  3. 3. Choose your output. Beautify re-prints the document with indentation; Minify collapses it to a single line. Open the options panel to pick two spaces, four spaces or tabs.
  4. 4. Apply any transforms. Sort keys, escape unicode, or remove null and empty properties if you want them — all optional, all off by default.
  5. 5. Take the result. Copy it, download it as data.json or data.min.json, print it, or press Swap to move the output back into the input and keep working on it.

To reformat an entire file in place, turn on Format on paste — the input is beautified the moment valid JSON lands in it. If you know this job as beautifying rather than formatting, the JSON beautifier is the same tool under that name.

How JSON validation works

Validation is parsing. The document is read left to right and broken into tokens — braces, brackets, colons, commas, strings, numbers and the three bare words true, false and null. Those tokens are then checked against the JSON grammar: a value, then optionally a comma and another value, until the container closes.

The moment a token appears where the grammar does not allow it, parsing stops. The position of that token is the error position, which is why a good validator can give you a line and a column rather than a vague complaint. Consider:

Invalid — the parser stops on line 4
{  "id": 1,  "tags": ["a", "b"],}

After the comma on line 3, the grammar requires another property. Instead it finds }, so the document is rejected with “Unexpected comma at line 3” and the explanation that trailing commas are not allowed. The fix is to delete one character.

Two details are worth knowing. First, the reported position is where the parser noticed the problem, which is not always where you made it — an unclosed brace on line 12 is usually reported at the end of the file, because that is the first point at which it becomes impossible to continue. Second, validation only checks syntax. It confirms the document is well-formed JSON; it does not check that it matches a schema, that email holds an email address, or that a required field is present. For that you need JSON Schema, which is a separate layer on top.

JSON formatting best practices

  • Pick one indentation and keep it. Two spaces is the most common convention and keeps deep documents narrow. What matters is that a repository does not mix styles — that produces diffs full of whitespace noise.
  • Minify in transit, format at rest. Send the small version over the network; keep the readable version in source control where humans review it.
  • Sort keys when you need stable diffs. If two services serialise the same object with different key orders, sorting makes them comparable.
  • Never allow duplicate keys. They parse, but the earlier value is silently discarded. Treat any duplicate as a bug in whatever produced the document.
  • Use UTF-8 and leave characters unescaped. JSON is UTF-8 by default and "café" is perfectly valid. Only escape to \uXXXX when a downstream system genuinely requires ASCII.
  • Keep numbers in range. JSON numbers are arbitrary precision on paper, but most parsers read them as 64-bit floats. Identifiers beyond 253 should be strings, or they will quietly lose their last digits.
  • Prefer omitting a field to sending null— unless null carries meaning of its own, such as “explicitly cleared”. Being consistent about which you mean saves a lot of defensive code downstream.
  • Remember JSON has no comments. If a file needs explanation, add a _comment property or keep the notes alongside it. JSONC and JSON5 allow comments but are not JSON, and standard parsers will reject them.

Common JSON errors

Nearly every invalid document fails for one of these six reasons. Each example below is rejected by any standards-compliant parser, with the correction beside it.

Missing comma

Two properties sit next to each other with nothing between them. Every property in an object, and every item in an array, must be separated by a comma.

Invalid
{  "id": 1  "name": "Ada"}
Valid
{  "id": 1,  "name": "Ada"}

Missing quotation mark

A string is missing its opening quote, so the parser reads Ada as a bare word. All JSON strings, including property names, need a double quote at both ends.

Invalid
{  "id": 1,  "name": Ada"}
Valid
{  "id": 1,  "name": "Ada"}

Trailing comma

A comma follows the last property. JavaScript allows this and so do most linters, but standard JSON does not — the comma promises another value that never arrives.

Invalid
{  "id": 1,  "name": "Ada",}
Valid
{  "id": 1,  "name": "Ada"}

Mismatched brackets

An array was opened with [ but closed with } — or never closed at all. Every bracket and brace must be closed by its own matching pair, in order.

Invalid
{  "tags": ["a", "b"}
Valid
{  "tags": ["a", "b"]}

Invalid escape character

Inside a string, a backslash starts an escape sequence. Only \" \\ \/ \b \f \n \r \t and \uXXXX are valid, so a literal backslash has to be doubled.

Invalid
{  "path": "C:\Users\ada"}
Valid
{  "path": "C:\\Users\\ada"}

Duplicate keys

This parses, but ambiguously: the specification does not define which value wins, and in practice the last one silently replaces the first. Rename one key or remove it.

Invalid
{  "id": 1,  "id": 2}
Valid
{  "id": 2}

Frequently asked questions

Is this JSON formatter free?

Yes. Every feature — beautifying, minifying, validating, the tree view, statistics, uploads and downloads — is free with no account, no usage limit and no paid tier. There is nothing held back.

Does my JSON get uploaded to a server?

No. Parsing, formatting and validation all run in your browser using JavaScript. The JSON you paste, drop or upload is never sent over the network, never stored and never logged. You can confirm this by opening your browser's network panel, or by disconnecting from the internet after the page loads — the tool keeps working.

What is the difference between formatting and validating JSON?

Validating answers whether the text is legal JSON, and if not, where it breaks. Formatting rewrites valid JSON with consistent indentation and spacing so it is easier to read. This tool does both at once: it validates as you type and shows the formatted result the moment the document parses.

Can I format very large JSON files?

Yes. Documents up to roughly 20 MB are supported. Anything over about 120 KB is parsed and formatted in a background Web Worker so the page stays responsive while it works, and the editor only renders the lines currently on screen rather than the whole file.

Can I minify JSON as well as beautify it?

Yes. Minify strips every optional space and line break to produce the smallest valid representation, which is what you want for network payloads and storage. The statistics tab shows exactly how many bytes that saves against your input.

Is my data secure?

Nothing leaves the tab, so there is no transfer to intercept and no copy on a server to breach. That said, the page itself is ordinary web software: if you are handling regulated or highly sensitive data, follow whatever policy your organisation has for pasting it into any browser tool.

Can I upload a JSON file?

Yes. Use the upload button, or drag a .json file straight onto the editor. The file is read locally with the browser's FileReader API — it is not transmitted anywhere. Files up to 20 MB are accepted.

Does this support deeply nested JSON?

Yes. The parser and the formatter are both iterative rather than recursive, so nesting depth is limited only by available memory rather than by the JavaScript call stack. Documents tens of thousands of levels deep parse without error. Past 512 levels the indentation stops widening, since lines would otherwise become unreadably long, but the output is still valid JSON.

What indentation should I use — two spaces, four spaces or tabs?

Two spaces is the most common convention for JSON and keeps deeply nested documents narrow. Four spaces reads more clearly at shallow depths. Tabs let each reader choose their own width and are friendlier to screen readers and people who need larger indents. Any of the three is valid; consistency within a project matters far more than the choice.

Why does the formatter reject JSON that works in my JavaScript file?

JavaScript object literals are more permissive than JSON. Unquoted keys, single-quoted strings, trailing commas, comments and values like undefined or NaN are all legal JavaScript but invalid JSON. The validator names whichever one it finds so you can see exactly which JavaScript-only habit crept in.

What happens to duplicate keys?

The specification permits duplicate keys but does not say what they mean, and in practice every parser keeps the last one and discards the earlier values. This tool flags each duplicate with its path and line number so you can decide, rather than silently losing data in the output.

Does formatting change my data?

By default, no — only whitespace changes, and the parsed values are identical. The optional clean-up settings do change the document: sorting keys reorders properties, escaping unicode rewrites non-ASCII characters as \uXXXX escapes, and the remove-null and remove-empty options delete properties. All four are off unless you turn them on.

Can I sort JSON keys alphabetically?

Yes. Turn on 'Sort object keys' in the options panel and every object is emitted in alphabetical order at every level of nesting. This is useful for producing stable output that diffs cleanly between two versions of the same document.

Does the tool work offline?

Once the page has loaded, yes. All the processing is local, so you can disconnect and keep formatting. You only need a connection to load the page in the first place.

Which JSON standard does this follow?

RFC 8259, the current specification for JSON, which matches what JSON.parse accepts in browsers and Node.js. Extensions such as JSON5, JSONC comments and trailing commas are deliberately rejected — if the validator says a document is valid here, every standards-compliant parser will accept it too.

Popular tools

↑ ↓NavigateOpenEscClose