esc

JSON Formatter & Validator

Format JSON online, validate JSON syntax, minify payloads, sort keys and inspect parse errors in your browser.

Indent
Input
0 B
Output
Valid JSON — lines — nodes — depth —
Tree explorer
Guide

Format, validate and minify JSON

JSON (JavaScript Object Notation) is a strict text format: keys and string values must use double quotes, there are no trailing commas, comments are not allowed, and the document is a single value — usually an object or array, although a lone string, number, true, false or null is also valid JSON. This JSON formatter and validator re-indents valid JSON so the structure is readable and points to the line and column where parsing fails.

Beautify expands the document with consistent indentation and one value per line — ideal for reading and diffing. Minify strips every non-essential character to produce the smallest payload for transport. Sort keys helps compare API responses and configuration files; for natural ordering, pinned keys and exact number preservation use the JSON Sort tool. All parsing runs entirely in your browser; the JSON you paste is not uploaded.

Examples

JSON formatter examples

Fixing a JavaScript-style object

Objects copied from JavaScript code or a config file often look like JSON but are rejected by a strict parser:

{ 'user': { id: 42, roles: ['admin', 'dev'], }, active: true }

The status bar switches to Invalid JSON and shows the parser message with a line and column — here line 1, column 3, the first single quote. Wrap every key in double quotes, replace the single-quoted strings and drop the trailing comma after the array:

{"user":{"id":42,"roles":["admin","dev"]},"active":true}

Beautified result and statistics

With the default 2-space indent, the corrected document formats to 10 lines. The status bar reports 6 nodes (the keys user, active, id, roles plus the two array items), depth 4 (root object → user → roles → array item) and a size of 99 B. Pressing Minify on the same input produces the single-line version above, which is 56 B.

Results

Reading the JSON output, status bar and tree

  • Valid JSON / Invalid JSON — whether your browser's native JSON.parse accepted the input. When parsing fails, the output and tree are cleared so stale results never sit under an error.
  • Lines — line count of the formatted output (always 1 after Minify).
  • Nodes — every object key and every array item, counted recursively. The root itself is not counted.
  • Depth — nesting levels, counting the root as 1 and the deepest value as its own level. A flat object such as {"a":1} has depth 2.
  • Size — UTF-8 byte size of the output. The badge on the input pane shows the size of what you pasted, so you can compare before and after minifying.
  • Tree explorer — a collapsible view of the parsed value. Objects show { } and arrays show [ ] with their child count; array items are labelled by index. Collapse all keeps the root open.

Copy and Download (saved as formatted.json) use the plain formatted text, without the line-number gutter.

Use cases

When to use a JSON formatter

  • Reading API responses. Paste a minified response from curl or browser dev tools to see its structure and find a nested field in the tree.
  • Validating config before a deploy. Catch a trailing comma or missing quote in a JSON config file before a service refuses to start.
  • Comparing two payloads. Turn on Sort keys and format both documents with the same indent so a diff shows only real differences. For natural ordering or pinned keys, use JSON Sort.
  • Shrinking payloads. Minify a fixture or request body before embedding it in a test, an environment variable or a curl command.
  • Inspecting encoded JSON. The payload of a JWT is JSON; the JWT Decoder extracts it, and Base64 Encode / Decode helps when JSON arrives Base64-encoded.
Troubleshooting

Troubleshooting invalid JSON

Symptom Likely cause Fix
Error points at a closing } or ] Trailing comma after the last item Remove the comma
Error at the first character of a key Unquoted or single-quoted key Wrap keys in double quotes
Error at / or # Comments (JSONC, JSON5 or YAML habits) Delete comments; JSON has none
Error at NaN, Infinity or undefined JavaScript values that JSON does not define Use null, a number or a string
Error at the very start of text that looks fine Invisible byte-order mark (BOM) or a log prefix before the JSON Re-save without BOM or trim the prefix
Error inside a string value Raw line break or tab, or an unescaped " Escape as \n, \t, \"

The error wording comes from your browser's JSON engine, so Chrome, Firefox and Safari phrase it differently. The line and column show where parsing stopped, which is usually at or just after the real mistake.

Limitations

JSON formatter limitations

  • Numbers are re-serialized. Values pass through JavaScript numbers, so integers above 253 lose precision (9007199254740993 becomes 9007199254740992) and notation is normalized (1.50 → 1.5, 1e3 → 1000). If exact digits matter, keep the original text or use JSON Sort, which preserves numbers exactly.
  • Duplicate keys are collapsed. If an object repeats a key, the last value wins and the earlier one silently disappears from the output.
  • Escapes may change. \u00e9 is output as é and \/ as /. The data is identical, but a byte-for-byte diff against the original will differ.
  • Sort keys is a plain code-unit sort. Uppercase keys come before lowercase, item10 sorts before item2, and integer-like keys such as "2" and "10" always come first in numeric order. Array order is never changed.
  • Syntax only. The validator checks JSON syntax, not a JSON Schema, required fields or value types. JSON5 and JSONC extensions such as comments or unquoted keys are rejected, and so is newline-delimited JSON (several documents on separate lines).
FAQ

Frequently asked questions

Is my data uploaded anywhere?

No. Parsing, formatting, minifying, sorting and validation all run client-side in your browser using the native JSON engine. Nothing is sent to a server.

Why does my JSON validator say invalid when it looks fine?

The usual culprits are trailing commas, single quotes instead of double quotes, unquoted keys, or comments — all valid in JavaScript objects but not in JSON. The error message points to the exact line and column where parsing stopped.

What does "sort keys" do?

It recursively reorders every object's keys alphabetically before formatting. This makes two JSON documents directly comparable in a diff even when the original key order differed.

Is there a size limit?

Everything runs in your browser, so the practical limit is your device memory. Documents up to a few megabytes format instantly; very large files may take a moment to build the tree view.

Why did a large number change after formatting?

The formatter parses numbers as JavaScript numbers, which are exact only up to 2^53 (9007199254740991). Larger integers, such as 64-bit IDs, are rounded, and notation like 1.50 or 1e3 is normalized to 1.5 or 1000. Send large IDs as strings, or use JSON Sort, which preserves numbers exactly.