JSON Formatter
Format, validate, and minify JSON. Pretty-print with 2 or 4 spaces or tabs, sort object keys, collapse to one line, and get error diagnostics with line and column numbers.
How to Use
- Paste JSON into the input pane (or load text from clipboard with Ctrl/Cmd+V).
- Pick the indent style: 2 spaces, 4 spaces, tab, or 0 (minify).
- Toggle "Sort keys" to alphabetize keys recursively for stable diffs and clean comparisons.
- The output pane updates instantly. Errors show the failing line and column with a hint about what went wrong.
- Copy the formatted output with the copy button or right-click and save.
- Everything runs in your browser — nothing is transmitted or logged.
Tips & Tricks
A Brief History of JSON
JSON (JavaScript Object Notation) was created by Douglas Crockford in the early 2000s as a lightweight alternative to XML for browser-server communication. The format wasn't invented so much as noticed — Crockford realized that a subset of JavaScript's object literal syntax (with the comma and quote rules tightened up) was already a complete data interchange format that any language could parse easily. He registered jsons.org in 2002 to publish the spec; ECMA standardized it in 2013, and ISO ratified it in 2017. The grammar fits on the back of a business card.
JSON's rise tracked the rise of AJAX (the asynchronous-JavaScript-and-XML pattern that powered Gmail and Google Maps starting in 2004) and especially the rise of REST APIs in the 2010s. By 2015 it was the de facto standard data format for the web, displacing XML in nearly every new system. Its triumph was so complete that the AJAX pattern is now almost always JSON-over-HTTP, with XML reserved for legacy systems and a handful of specialized formats (SOAP, RSS, OOXML).
The strict spec — no comments, no trailing commas, no unquoted keys — has been the source of long-running developer complaints, and several relaxed variants (JSON5, JSONC, HJSON, YAML) have arisen to address them. None has displaced strict JSON for interchange; the strictness is what makes the format universally interoperable across thousands of language implementations.
About This Formatter
This formatter uses the browser's native JSON.parse and JSON.stringify functions — the same parser that Node.js, V8, and every modern browser ships with. Pretty-printing chooses the indent character and width; minification strips all optional whitespace; key sorting recursively alphabetizes object keys for stable diffs. Errors are surfaced from the native parser with line and column reported when available.
Everything runs entirely in your browser. The JSON you paste is never transmitted to a server, logged, or stored — you can safely format API responses, config files, and other potentially sensitive data. For files larger than a few MB, the textarea may become sluggish; for those, use jq or a desktop editor with proper streaming support.
Frequently Asked Questions
Why won't my JSON parse?
Most common causes: trailing commas after the last item in an array or object, single quotes instead of double quotes, unquoted keys, comments (which are not valid JSON), and stray characters from copy-paste. The error message points to the exact line and column. JSON5 and JSONC (JSON with Comments) are popular relaxed variants but they are not accepted by strict JSON parsers like the one this tool uses.
What's the difference between 2-space and 4-space indentation?
Pure convention. JavaScript and most npm packages use 2 spaces. Python's json.dumps default is 4. Some style guides prefer tabs because they let each developer choose their own visual width. Pick whatever your project's linter or .editorconfig specifies; for ad-hoc API responses, 2 spaces gives more compact output.
When should I sort keys?
For deterministic diffs (e.g., committing config files to git), comparison testing (snapshot tests, integration test fixtures), and any scenario where two semantically-equal JSONs should look identical. Object key order is technically not significant in JSON, but unsorted output can produce noisy diffs.
Can I edit the JSON in the formatter?
Yes — the input box is editable, and re-parsing happens as you type. For larger structures use a real editor with JSON syntax support (VS Code, JetBrains IDEs); this tool is for quick formatting, validation, and copying.
How big a JSON can it handle?
Several MB easily. The native JSON.parse and JSON.stringify in modern browsers are very fast. Multi-hundred-MB files may be slow to render in the textarea; for those use a streaming parser or jq instead.
Is my data uploaded anywhere?
No. The formatter runs entirely in your browser using the standard JSON.parse and JSON.stringify functions. Nothing is sent to any server, logged, or stored. You can safely paste API responses, config snippets, or sensitive data.
Common Use Cases
Inspecting API responses
Paste a raw response from curl or your browser DevTools, format it for readability, and find the field you need.
Cleaning up config files
Pretty-print package.json, tsconfig.json, or any config file before committing it to keep diffs clean.
Validating before posting
Catch syntax errors in JSON payloads before they hit your server's parser and produce cryptic 400-series errors.
Minifying for transmission
Strip whitespace from JSON before embedding it in URLs, query strings, or storage where bytes matter.
Comparing two responses
Sort keys and pretty-print two JSON blobs identically so a regular text-diff tool can highlight only the real differences.
Teaching and documentation
Format example payloads consistently when writing API documentation, blog posts, or tutorials.
Last updated: