Skip to content

JSON Formatter & Validator

Format, validate and minify JSON in your browser. Pinpoints syntax errors by line and column, sorts keys for clean diffs, and never uploads your data.

Input

Output

Output appears here as you type.

About the JSON Formatter & Validator

A JSON formatter turns a single unreadable line of JSON into indented, reviewable text — and tells you exactly where the syntax breaks when it will not parse. This one runs entirely in your browser: the payload you paste is never uploaded, logged or stored, which matters when the thing you are debugging is a production API response with real customer data in it.

JSON's grammar is defined by RFC 8259, and it is stricter than it looks. Object keys must be double-quoted strings, never bare identifiers or single-quoted text. Trailing commas after the last element are a syntax error, not a style choice — unlike a JavaScript object literal, where `{a: 1,}` is fine. Comments have no place in the grammar at all, which is why a `tsconfig.json` full of `//` comments is technically JSONC, not JSON, and needs stripping before a strict parser will accept it.

Validity is decided by the browser's own native JSON.parse — the same parser your code will actually run against, so there is no risk of this tool accepting something your application rejects, or vice versa. Locating the error is a separate problem: V8, SpiderMonkey and JavaScriptCore each report a different message for the same mistake, and the most common one — a trailing comma — comes back from V8 with no position at all. So after the native parse fails, this tool re-scans the input with its own scanner built specifically to answer one question: where, precisely, does this stop being valid JSON.

Beautify mode re-indents with 2 spaces, 4 spaces or a tab. Minify mode strips every byte of insignificant whitespace, which is what you want before pasting a fixture into a test or measuring a response payload. Both modes parse through the same native JSON.parse first, so anything that formats or minifies here is guaranteed valid JSON — the tool cannot silently "fix" broken input into something that merely looks right.

  • Syntax errors reported with line and column, plus the offending line and a caret under the exact character — even for the trailing-comma case Chrome reports without a position
  • Optional key sorting for stable diffs between two API responses — array order is left untouched, since that order is data, not formatting
  • Live stats: key count, array count, node count and nesting depth, computed with an iterative walk so deeply nested payloads do not blow the call stack
  • Byte size before and after, so you can see what minifying actually saves
  • Download the result as a .json file, or copy straight to the clipboard
  • Paste directly from the clipboard with one click, for payloads too large to comfortably select and copy from DevTools

How to use it

  1. Paste your JSON into the input pane, or press Load sample to try it.
  2. Pick Beautify to indent it, or Minify to strip whitespace.
  3. Choose an indent width — 2 spaces, 4 spaces or a tab — to match your project's style.
  4. Turn on Sort keys if you are comparing two payloads and want key order to stop causing false diffs.
  5. Copy the result, or download it as a .json file.

Real-world use cases

Backend & API developers

Paste a raw API response to read its structure at a glance, or minify a fixture before checking it into a test suite where every byte of diff noise makes a future code review harder.

Frontend developers

Beautify a config file or a response body copied out of the Network tab, where DevTools shows it as one unreadable line, to actually see what you are working with before writing the code that consumes it.

QA & test engineers

Sort keys on two API responses before diffing them, so key-order differences — which mean nothing in JSON — stop generating false positives in a manual comparison.

DevOps & platform engineers

Validate a Terraform variables file, a Kubernetes ConfigMap value or a CI pipeline's JSON output locally, without pasting production configuration into a third-party service.

Technical writers & API documentarians

Confirm that a JSON example destined for documentation actually parses — catching the trailing comma or curly quote a word processor introduced before a reader copy-pastes it and hits an error.

Examples

Beautify a minified response

Input
{"id":42,"tags":["a","b"],"meta":{"ok":true}}
Output
{
  "id": 42,
  "tags": [
    "a",
    "b"
  ],
  "meta": {
    "ok": true
  }
}

Locate a syntax error

Input
{
  "name": "Ada",
  "roles": ["admin",]
}
Output
Trailing comma before ] — line 3, column 21

  "roles": ["admin",]
                    ^

JSON does not allow trailing commas, unlike JavaScript object literals. This is the single most common reason a hand-edited config file fails to parse — and the case where the browser's own error message is least helpful, since Chrome reports it without a position at all.

Sort keys for a stable diff

Input
{"b":2,"a":1,"c":[3,2,1]}
Output
{
  "a": 1,
  "b": 2,
  "c": [
    3,
    2,
    1
  ]
}

Object keys are reordered alphabetically at every level. The array [3,2,1] is left exactly as written — array order carries meaning, so sorting it would change the data, not just its formatting.

A duplicate key

Input
{"status":"pending","status":"done"}
Output
{
  "status": "done"
}

JSON.parse silently keeps only the last occurrence of a duplicate key — this is standard behaviour across every mainstream JSON parser, not a bug in this tool. If a duplicate key is the actual problem you are debugging, it will already have been discarded by the time you see the beautified output; the fix is to grep the raw text for the key name before formatting it.

Common errors

MessageCauseFix
Unexpected token } in JSONA trailing comma before a closing brace or bracket.Delete the comma after the last property or array element.
Unexpected token ' in JSONSingle-quoted strings or keys. JSON only accepts double quotes.Replace every ' with ". Keys must be quoted too — {name: 1} is invalid.
Unexpected end of JSON inputThe document is truncated — usually a copy that missed the last characters, or a streamed response that was cut off.Re-copy the full payload and check that braces and brackets balance.
Unexpected token N in JSONA JavaScript value that is not valid JSON, such as NaN, Infinity or undefined.Replace it with null, or a number/string the consumer expects.
Unexpected non-whitespace character after JSONTwo documents concatenated, or JSON Lines (one object per line) pasted as a single document.Format one document at a time, or wrap the lines in an array separated by commas.
Unexpected token / in JSONA // or /* */ comment in the input — valid in JSONC files like tsconfig.json, but not in strict JSON.Strip the comments before pasting. This tool parses strict JSON only, which is what makes its error locations precise.

Frequently asked questions

Is my JSON uploaded to a server?

No. Parsing and formatting happen in your browser using the built-in JSON parser. Nothing is sent over the network, so you can safely paste production payloads, tokens and personal data.

What is the difference between beautifying and minifying JSON?

Beautifying adds newlines and indentation so a human can read the structure. Minifying removes all whitespace between tokens to make the payload as small as possible. Both produce identical data — only the formatting differs.

Why does my JSON fail to parse when it works in JavaScript?

JSON is stricter than JavaScript object syntax. It forbids trailing commas, single-quoted strings, unquoted keys, comments, and the values NaN, Infinity and undefined. Anything valid in a .js file is not automatically valid JSON.

Does sorting keys change my data?

No. Object key order is not significant in JSON, so sorting keys produces an equivalent document. Array element order is left untouched, because that order is data.

Can it handle large files?

Files up to a few megabytes format instantly. Much larger documents are limited by your browser's memory rather than by the tool, since everything is processed locally.

Does it support JSON5, JSONC or comments?

Not currently — the parser is strict JSON, which is what makes the error messages precise. Strip // and /* */ comments before pasting a tsconfig.json or similar JSONC file.

What happens to duplicate keys in an object?

The native JSON.parse keeps only the last value for a repeated key and silently discards the earlier ones — this tool does not change or restore that behaviour, since it is standard across virtually every JSON parser. If you need to catch duplicate keys before they are lost, check the raw text before formatting.

Will large numbers lose precision?

Yes, if they exceed 2^53 (about 9 quadrillion) — this is a property of JavaScript's number type, not something specific to this tool. A large integer ID from a system that uses 64-bit numbers (some database primary keys, Snowflake IDs) can come back rounded after a JSON.parse/stringify round trip. If exact precision matters, keep the value as a JSON string rather than a bare number at the source.

Last updated