What this page actually does
This editor takes a JSON string, parses it with the browser’s JSON.parse, then writes it back with JSON.stringify. Pretty-print adds indentation. Minify (Raw) writes the same data with no extra whitespace. Neither mode changes keys, values, or array order.
Validation is the same parse step: if the string is not legal JSON, the editor shows the exception instead of rewriting the document. That is useful when an API response, package.json, or config paste fails because of a trailing comma, single quotes, or a truncated copy.
What is JSON and why does formatting matter?
JSON (JavaScript Object Notation) is a lightweight text format for structured data. It is the default exchange format for REST APIs, GraphQL responses, mobile apps, serverless functions, and configuration files such as package.json, tsconfig.json, and many CI/CD manifests.
JSON is built from a small set of values: objects ({}), arrays ([]), strings, numbers, booleans (true/false), and null. Because nesting can go many levels deep, a single missing character can invalidate an entire document. Formatting does not invent new rules—it surfaces the structure so you can see keys, arrays, and nesting at a glance.
Pretty-print vs minify
- Pretty-print (beautify) — adds indentation and newlines. Best for debugging, code review, documentation, and editing configs by hand.
- Minify (compact) — removes unnecessary whitespace. Best for production APIs, CDN assets, and reducing transfer size while keeping identical data.
Both modes must produce valid JSON. If the input is invalid, formatting should fail loudly so you can fix the syntax instead of shipping broken data.
How to use this JSON formatter
- Paste, type, or Upload a
.json/.txtfile into the left editor (or click Sample). - Click Valid if you only want a parse check, or Format to pretty-print using the Indent menu (2, 4, or 8 spaces, or Tab).
- Switch the output tab to Tree to expand nested objects and arrays without scrolling a long pretty-print.
- Click Minify for a compact string, then Copy or Save (downloads the output as a file).
- Use Extract when the JSON is buried in HTML, logs, or PHP dump text.
With the CodeMirror editor focused, Ctrl+Enter or Ctrl+S runs Format. Search inside a pane with the search control (Ctrl+F when that binding is available).
Features that help you work faster
JSON validator
Validation answers a binary question: “Is this legal JSON?” Invalid documents fail immediately with a clear error message so you can locate the problem. Common failures include trailing commas (allowed in JavaScript objects, not in strict JSON), single quotes instead of double quotes, unquoted keys, and comments (// or /* */), which are not part of the JSON standard.
Tree view / JSON explorer
Large API responses can be thousands of lines long. A JSON tree viewer lets you expand only the branches you care about—ideal for inspecting nested data, errors, or pagination objects without scrolling through an entire pretty-printed file.
Extract JSON from mixed text
Logs, HTML error pages, and PHP dump output often bury a JSON object inside other text. The Extract action helps pull the JSON fragment out so you can validate and format it instead of cleaning the string by hand.
Privacy-first, client-side processing
Parse, format, minify, tree view, extract, copy, and save all run in the browser. Choosing Upload reads the file locally; it is not sent to a conversion API. The page still loads the CodeMirror editor from a CDN, and any browser extension can see the DOM. Do not paste production secrets into a shared machine.
Common JSON errors and how to fix them
- Unexpected token / Unexpected end of JSON — usually a missing
}or], or a truncated paste. Count opening and closing braces, or re-copy the full payload. - Trailing comma — remove the comma after the last property in an object or the last item in an array.
- Single quotes — JSON strings and keys must use double quotes (
"), not single quotes ('). - Unescaped characters — quotes and backslashes inside strings must be escaped (e.g.
\",\\). Newlines inside strings should use\n. - Undefined / NaN / functions — these are JavaScript values, not valid JSON. Convert them to
null, numbers, or strings before formatting. - Comments — strip
//and block comments, or convert the file to a format that allows comments (JSONC/JSON5) using a dedicated parser—not standard JSON.
When this editor is the right tool
Use it for a one-off payload: a curl or Postman body, a broken config paste, or a log line that still contains a JSON object. Keep using jq, Prettier, or format-on-save for files that already live in a repository.
Very large documents are limited by browser memory. Tree view helps navigation, but tens of megabytes of JSON may freeze the tab. There is no server-side pretty-print fallback on this page.
JSON formatting best practices
- Validate before you minify; never ship invalid compact JSON.
- Pick one indent style (commonly 2 spaces) and stay consistent in docs and examples.
- Keep secrets out of shared screenshots and public tickets—even when processing is local.
- For large payloads, use Tree view to navigate, then copy only the branch you need.
- Store human-edited configs pretty-printed in git; minify only at the transport or build step when size matters.
Related developer tools
After the document is valid, Text Compare diffs two JSON versions side by side. Regex Tester is useful when you need to pull fields out of a string before it is valid JSON. Other developer tools and the full catalog sit one click away.
JSON formatter FAQ
Does formatting change my data?
No. The editor parses then stringifies. Keys, values, and array order stay the same; only whitespace changes between pretty and minify.
Which indent sizes exist?
The Indent menu offers 2 spaces (default), 4 spaces, 8 spaces, or Tab.
What does Extract do?
It looks for a JSON object or array buried in HTML, logs, or PHP dump text, then loads that fragment so you can validate it.
Why did Format fail?
JSON.parse rejected the string. Typical causes: trailing commas, single quotes, comments, truncated paste, or unquoted keys.
Is the payload uploaded?
No. Parse and stringify run in the browser. Upload reads a local .json/.txt file. CodeMirror is loaded from a CDN.
Can I diff two JSON files here?
No. Use Text Compare after both sides are valid.