JSON Formatter Online

Unreadable JSON is a rite of passage — this tool ends it. Paste any JSON into this free JSON formatter online to pretty-print it with clean 2-space indentation, minify it for production, or validate it with exact line-and-column error locations. You also get useful stats: total key count, maximum nesting depth, and size in bytes. Everything runs in your browser; your data never leaves the page.

Format, Minify & Validate JSON

Actions

How to Use the JSON Formatter Online

One textarea, five buttons, zero learning curve:

  1. Paste your JSON into the big input box — straight from an API response, a config file, or your editor. Not sure what to try? Hit Load sample for a realistic example.
  2. Choose an action. Format JSON pretty-prints with 2-space indentation; Minify strips all unnecessary whitespace for production payloads; Validate checks correctness and shows only the stats; Clear resets everything.
  3. Read the results. Valid JSON gets a green-light summary — key count, maximum nesting depth, and byte size — plus the transformed output in a scrollable code block. Invalid JSON gets the offending line highlighted with a caret pointing at the exact column, so you fix it in seconds.

The output area has Copy and Share buttons built in, so moving formatted JSON back into your editor or a chat thread is one click. Because validation runs on every change, you can also paste first and fix live: correct the highlighted line, and the error display updates as you type until the JSON turns valid.

How JSON Validation and Formatting Work

Under the hood, this tool uses your browser's native JSON.parse — the same strict parser your JavaScript code uses — so "valid here" means "valid in your app." Formatting is JSON.stringify with 2-space indentation, which normalizes key order (it preserves the original order), spacing, and number representation into one canonical, readable layout. Minifying is the same call with no indentation, producing the smallest correct representation.

Error pinpointing works by reading the parser's message. Modern engines report failures like "Unexpected token } in JSON at position 42" — the tool extracts that position, walks the input to find the corresponding line and column, and renders the surrounding lines with the broken one highlighted and a ^ caret under the exact character. For "unexpected end of input" (truncated JSON), it points at the end of the text, which is where the missing bracket or quote belongs.

The stats are computed by walking the parsed structure once: every object key is counted (including nested ones), the deepest nesting level becomes the max depth (a flat object is depth 1), and the size is measured in UTF-8 bytes — the number that actually matters for payload budgets. These three numbers answer the questions developers ask most about an unfamiliar payload: how big is it, how complex is it, and how much of it will I have to map?

Worked Example

Click Load sample and the tool fills in this object (deliberately shown unformatted here):

StepActionResult
1. Paste{"name": "Ada Lovelace", "role": "Developer", "active": true, "score": 98.6, "tags": ["json","api","tools"], "address": {"city": "London","zip": "E1 6AN"}, "notes": null}Raw one-line JSON
2. Format2-space indentation applied9 readable lines; nested address object clearly visible
3. StatsStructure analyzed8 keys, max depth 2 (root → address), size in bytes shown
4. MinifyWhitespace strippedCompact single line, ready to paste into a request body
5. Break itDelete the closing } and watchInvalid JSON — caret points at the end of the last line where the brace belongs

The depth-2 reading is the useful one: it tells you at a glance that this payload nests two levels deep, so mapping it in code means at most two dots of access (obj.address.city). Payloads deeper than 4 or 5 levels are usually a sign the API response could be flattened — the depth stat makes that visible instantly.

Limitations

This tool enforces strict JSON (RFC 8259), exactly like JSON.parse. That means no comments, no trailing commas, no single-quoted strings, no unquoted keys, and no special values like NaN, Infinity, or undefined — all of which appear in JSON-like formats (JSON5, JavaScript object literals, some config files) but are not valid JSON. If your input uses those, convert it to strict JSON first.

Duplicate keys are technically allowed by the spec but the parser keeps only the last value, and the key counter counts each occurrence — treat duplicates as a bug in your data. Very large inputs (tens of megabytes) will parse but may feel sluggish, since everything runs on the browser's main thread; for huge files, a streaming parser in Node.js is the better tool. Finally, validation confirms syntax, not schema: it cannot tell you whether a required field is missing or a value has the wrong type — that is a job for JSON Schema validation.

Sources & References

This tool validates against the JSON grammar itself, in your browser, using the same parsing rules as JavaScript’s built-in JSON object. The references behind it:

  • MDN — JSON: Mozilla’s reference for the JSON data format and the JSON.parse / JSON.stringify methods.
  • JSON.org — Introducing JSON: the official grammar diagrams — the rules every valid JSON document has to follow.

Frequently Asked Questions

How do I format JSON online?
Paste your JSON into the input box and click Format JSON — the tool pretty-prints it with 2-space indentation and shows the result in a scrollable code block with a Copy button. If the JSON is invalid, you will see the exact line and column of the error instead, so you can fix it and re-format.
What is the difference between formatting and minifying JSON?
Formatting (pretty-printing) adds indentation and line breaks so humans can read the structure; minifying removes all unnecessary whitespace so machines transfer fewer bytes. The data is identical either way. Format while you are debugging, minify when you are shipping payloads or embedding JSON in size-sensitive places.
How do I find the exact location of a JSON error?
Paste the broken JSON and the tool highlights the offending line and places a caret (^) under the exact character the parser choked on, with the line and column numbers shown above. The most common culprits are a missing comma between properties, a missing closing bracket or brace, and an unescaped quote inside a string.
Why does JSON validation fail on single quotes or trailing commas?
Because strict JSON only allows double-quoted strings and forbids trailing commas — single quotes and trailing commas belong to JavaScript object literals and formats like JSON5, not to JSON itself. Replace single quotes with double quotes and remove the comma after the last item in each object or array, and the JSON will validate.
What do the key count and max depth stats tell me?
Key count is the total number of properties across the whole structure, including nested objects — a quick measure of how much data you are dealing with. Max depth is the deepest nesting level (a flat object is depth 1); it tells you how many levels of access like obj.address.city your code will need, and depths beyond 4 or 5 often signal a payload worth flattening.
Is my JSON data uploaded to a server?
No. Parsing, formatting, minifying, and validation all run locally in your browser with the built-in JSON engine — nothing is sent anywhere. You can safely format API responses containing tokens, customer records, or other sensitive data.

Guides for This Tool

Related Tools