JSON Formatter & Validator
Paste JSON to format it instantly: this JSON formatter pretty-prints and beautifies minified API responses, validates the syntax as you type and points to the exact position of any error. Minify it back, repair broken JSON, or convert it to YAML or CSV with one click.
Runs in your browser — nothing is uploaded.Unlike formatters that stored and leaked user pastes, your JSON stays on your device.
How to format JSON online
- Add your JSON — paste it or load a
.jsonfile. The file is read in your browser and never uploaded. - Read the status: "Valid JSON", or the parser's error message with the character position where parsing stopped.
- Choose an indent (2, 4, 6 or 8 spaces) and use the wand to beautify, or the minify button to collapse it to one line.
- Copy or download the result. Your input is kept in this browser's localStorage so it survives a reload or a switch to another JSON tool; the trash icon clears it.
Worked example: beautifying a minified API response
A typical response body from curl or a log line arrives on one line:
{"id":4821,"status":"active","owner":{"name":"Ada","email":"ada@example.com"},"tags":["beta","eu"],"limits":{"rpm":600,"burst":null}}Formatted with 2-space indentation it becomes:
{
"id": 4821,
"status": "active",
"owner": {
"name": "Ada",
"email": "ada@example.com"
},
"tags": [
"beta",
"eu"
],
"limits": {
"rpm": 600,
"burst": null
}
}Now the structure is obvious: owner is a nested object, tags an array, and burst is explicitly null rather than missing — a difference that matters when your code checks "burst" in limits.
Common JSON errors and how to fix them
The validator uses your browser's own JSON.parse, so the messages below are the ones Chrome, Edge and Node.js produce (Firefox and Safari word them differently). The position is a 0-based character offset.
| Input | Error message | Fix |
|---|---|---|
| {"a": 1,} | Expected double-quoted property name in JSON at position 8 | Trailing comma. Remove the last comma before } or ]. |
| {'a': 1} | Expected property name or '}' in JSON at position 1 | Single quotes. JSON strings and keys need double quotes. |
| {a: 1} | Expected property name or '}' in JSON at position 1 | Unquoted key, as in a JavaScript object literal. Quote it: "a". |
| {"a": 1 // note } | Expected ',' or '}' after property value in JSON at position 8 | Comments aren't allowed in JSON. Remove them (or use JSONC/JSON5 where supported). |
| {"a": NaN} | Unexpected token 'N', "{"a": NaN}" is not valid JSON | NaN, Infinity and undefined don't exist in JSON. Use null or a string. |
| {"a": "x" "b": 2} | Expected ',' or '}' after property value in JSON at position 11 | Missing comma between two properties, often after copy-pasting lines. |
If there are many errors — JSON copied from a JavaScript file, a Python repr(), or a truncated log — the JSON repair tool fixes quotes, commas and comments automatically. For a step-by-step approach, see how to fix broken JSON.
Why your JSON formatter should run in the browser
JSON is what developers paste when debugging: API responses with customer records, webhook payloads, config files with database URLs, and tokens copied from request headers. In 2025, watchTowr Labs showed that JSONFormatter.org and CodeBeautify.org had been storing users' saved pastes for years — more than 80,000 files and 5 GB of data, including passwords, API keys, SSH private keys and Active Directory credentials from banks, hospitals and government agencies. Read the full JSONFormatter and CodeBeautify leak breakdown.
Formatting JSON doesn't need a server: JSON.parse and JSON.stringify do it in milliseconds on your device. This formatter has no save or share links, no backend that receives your input, and keeps working if you load the page and go offline. That is the test worth applying to any tool you trust with real data.
Learn more
How to Fix Broken JSON: Common Errors and How to Repair Them
Trailing commas, single quotes, unquoted keys, comments — the 6 most common JSON parse errors explained with examples and exact fixes.
JSON vs XML: Which Should You Use for Your API?
JSON and XML both represent structured data, but they have very different strengths. Learn when to use each format, how they compare in size and verbosity, and which is right for your use case.
What Is Code Minification and Why It Matters for Web Performance
Minification removes whitespace, comments, and redundant code to reduce file size. Learn how CSS and JavaScript minification work, how much size they save, and what tools to use.
Related Tools
Frequently Asked Questions
Is it safe to paste JSON with API keys or customer data into an online formatter?▾
Only if the formatter runs in your browser. This one does: JSON.parse and JSON.stringify run on your device, there is no save or share feature that would need a server, and no request is made with your JSON. Server-side formatters are a proven risk — JSONFormatter.org and CodeBeautify.org kept users' saved pastes, and researchers found more than 80,000 of them (about 5 GB) containing passwords, API keys and cloud credentials. To check any tool, open DevTools → Network and watch for requests while you paste.
How do I pretty-print JSON in the terminal?▾
With jq: jq . file.json (add -S to sort keys, or --indent 4 for four spaces). With Python, no install needed: python3 -m json.tool file.json. With Node.js: node -e 'console.log(JSON.stringify(JSON.parse(require("fs").readFileSync(0, "utf8")), null, 2))' < file.json. To minify instead, use jq -c . file.json.
What indentation should I use when formatting JSON — 2 or 4 spaces?▾
Either is valid; JSON ignores whitespace between tokens. Two spaces is the most common convention in the JavaScript ecosystem (package.json, tsconfig.json, Prettier's default) and keeps deeply nested data readable on narrow screens. Four spaces is common in Python projects (json.dumps(indent=4)). What matters is consistency within a project, so diffs only show real changes.
Why does my JSON fail validation even though it works fine as a JavaScript object?▾
JavaScript object syntax is a superset of JSON — it allows things JSON strictly forbids: single-quoted strings, unquoted keys, trailing commas, comments, undefined values, and NaN/Infinity numbers. JSON (per RFC 8259) requires double-quoted keys and string values, no trailing commas anywhere, and only finite decimal numbers. When you copy a JS object literal directly into a JSON context (API body, config file), these differences cause parse failures.
What happens when a JSON object contains duplicate keys?▾
The JSON spec technically permits duplicate keys but defines no required behavior for handling them — it's left to the parser. In practice, most parsers silently use the last occurrence, but some use the first, and others throw an error. This means duplicate keys produce inconsistent results across languages and runtimes — a real portability bug even if the JSON technically parses locally. Note that formatting with this tool keeps only the last value, because it uses the browser's JSON.parse.
Can JSON represent numbers larger than Number.MAX_SAFE_INTEGER (2⁵³)?▾
The JSON spec has no numeric precision limits, but most parsers parse numbers into IEEE 754 doubles, which cannot exactly represent integers above 2⁵³ − 1 (9,007,199,254,740,991). If you parse a JSON payload containing a 64-bit integer ID (common in Twitter/X APIs or database row IDs), the value will silently lose precision. The correct fix is to transmit large integers as strings in the JSON, or use a parser with BigInt support.
When should I minify JSON, and how much space does it actually save?▾
Minifying removes all non-significant whitespace and newlines to produce the smallest possible valid JSON string. You would minify for production API responses or embedding in HTML/JS bundles where every byte matters — a 10 KB prettified JSON config can shrink to ~6 KB minified (roughly 40% reduction). For config files committed to source control, formatted JSON is far preferable for readability and diff clarity.
Why does my formatter change Unicode escape sequences like \u00e9 to é?▾
Both forms are valid — \u00e9 is a JSON Unicode escape and é is its literal UTF-8 representation. Formatters that normalize these are making a safe transformation, since modern systems handle UTF-8 directly. However, if your output must pass through a transport layer that isn't UTF-8 safe (some legacy SMTP gateways, certain XML parsers), keeping the \uXXXX escape form is the safer choice.