How to use the JSON Formatter
- Paste your JSON into the left textbox. Formatting begins automatically after you stop typing for 300ms.
- Choose your indent: 2 spaces (default), 4 spaces, tab, or minified (single line).
- Read the result in the right textbox. On parse errors, the status line shows exact line and column.
- Click Copy to copy the output, or use
Ctrl/⌘ + Shift + C.
What makes a JSON document "valid"?
Per RFC 8259, a valid JSON document is
exactly one of: an object, an array, a string, a number, true, false, or null.
Trailing commas are not allowed. Comments are not allowed. Strings must be double-quoted — single quotes are
invalid JSON even if JavaScript accepts them.
Common JSON errors and what they mean
"Unexpected token" errors
Almost always one of these four:
- Trailing comma —
{"a":1,}is invalid. Remove the final comma. - Single quotes —
{'a':1}is invalid. Convert to double quotes. - Unquoted keys —
{a:1}is invalid. Wrap keys in double quotes:{"a":1}. - JavaScript values —
undefined,NaN, andInfinityare not valid JSON. Usenull.
"Unexpected end of JSON input"
Usually a missing closing brace, bracket, or quote. Look for unbalanced {}, [], or "".
"Bad control character in string literal"
Raw newlines, tabs, or other control characters in strings must be escaped: use \\n for newline, \\t for tab.
Privacy and performance
Parsing happens entirely in your browser via the built-in JSON.parse. No data is transmitted to any server.
The browser's native parser processes hundreds of kilobytes of JSON in single-digit milliseconds — much faster than
any "online formatter" that round-trips to a server. You can inspect the JavaScript running this tool via your
browser's DevTools.
JSON minifier — when minified output is the right choice
The minified option (0-indent / single-line) in this tool strips all whitespace not required by the JSON spec. That is exactly what the JSON minifier does. Use it in these situations:
- Production API responses — minified JSON is typically 15–30% smaller than 2-space-indented output. On a high-traffic endpoint that returns 5 KB of JSON, minification shaves 1–1.5 KB per response, which compounds into meaningful bandwidth savings at scale.
- localStorage / sessionStorage — browser storage has a 5 MB quota per origin. Minifying JSON before writing reduces the chance of hitting that limit.
- Environment variables and CI secrets — some CI systems have length limits on secret values. A minified JSON config often fits where a formatted one doesn't.
- Log payloads — one JSON object per log line is the standard for structured logging. Minified keeps each line a single line.
Use the formatter (2-space or 4-space indent) during development and debugging, and the minifier for anything that goes to production or a byte-limited channel.
JSON formatter vs JSON linter — not the same thing
These terms are often used interchangeably but describe different operations:
- JSON formatter — takes valid JSON and rewrites it with consistent indentation and whitespace. It does not change the data; it only changes the presentation. If the input is already valid, formatting always succeeds.
- JSON linter — checks for structural correctness: balanced braces, valid string escapes, no trailing commas, no comments, no JavaScript-specific values like
undefinedorNaN. A linter catches errors; a formatter cannot fix them.
This tool does both. If the JSON is valid, it formats it. If the JSON is invalid, it shows a linter-style error message with exact line and column. You get a formatter and a validator in one step.
JSON in APIs — best practices
- Always set
Content-Type: application/json— clients use this header to decide how to parse the response. Omitting it causes framework-level bugs in some HTTP clients. - Consistent key naming — pick camelCase or snake_case and stick to it across the entire API. Mixing both in the same response is a common source of client bugs.
nullvs omitting a key — these have different semantics.{"middle_name": null}means the field exists but has no value.{}(key absent) means the client should make no assumption. Be deliberate — inconsistency here breaks client-side null checks.- Dates as ISO 8601 strings — JSON has no native date type. Represent dates and datetimes as strings in ISO 8601 format (
"2026-05-13T00:00:00Z"). Never use Unix timestamps as bare integers if humans will read the API — they're impossible to debug at a glance. - Avoid deeply nested structures — more than 3–4 levels of nesting is a sign the data model needs to be reconsidered. Deep nesting makes client-side destructuring verbose and error-prone.
JSON types reference
| Type | JSON syntax | JS equivalent | Notes |
|---|---|---|---|
| string | "hello" | string | Double quotes only. Escape \\, ", and control chars. |
| number | 42, 3.14 | number | No hex, no octal, no NaN, no Infinity. |
| boolean | true, false | boolean | Lowercase only. True is invalid JSON. |
| null | null | null | Lowercase only. Represents intentional absence of value. |
| array | [1, "a", true] | Array | Ordered. Can mix types. No trailing comma. |
| object | {"key": value} | Object | Unordered per spec, but most parsers preserve insertion order. |
Frequently asked questions
Does the JSON Formatter support JSON5 or JSONC (with comments)?
Not yet — this tool follows strict RFC 8259. JSON5 (with comments, trailing commas, single quotes) is planned as a separate mode. For now, if you paste JSON5, the error status will point at the offending character.
Can I format very large JSON files (100MB+)?
Browsers can parse JSON up to about 500MB before running into memory pressure, but the editor UI becomes
sluggish around 50MB of raw text. For multi-GB files, use a streaming parser like
jq or Node's stream-json.
Is the formatter deterministic?
Yes. For the same input and the same indent setting, output is byte-identical across runs and browsers.
Object key order is preserved as in the input (modern JSON.stringify respects insertion order).
Why does my JSON look different after formatting?
The formatter normalizes whitespace and preserves everything else. Numbers are re-serialized via
JSON.stringify, which means 1.0 in the input becomes 1 in the output
(both are the same number in JSON). Unicode escapes like \\u00e9 are converted to the
corresponding character (é) when that character is safely printable.
Can I use this offline?
Once the page has loaded, yes — everything runs in-browser. You can disconnect from the internet and the tool keeps working. Add the page to your bookmarks or use your browser's "install as app" option for one-click access.
Can I sort JSON keys alphabetically?
Not as a built-in option in this tool — the formatter preserves key order as-written, which is usually what you want (no surprise reordering of your data). To sort keys, use jq on the command line: jq -S . input.json (the -S flag sorts keys). Alternatively, in a browser console: JSON.stringify(JSON.parse(s), Object.keys(JSON.parse(s)).sort()) — though this only sorts top-level keys. For deep sorting: JSON.stringify(JSON.parse(s), (k, v) => v instanceof Object && !Array.isArray(v) ? Object.keys(v).sort().reduce((r, kk) => (r[kk]=v[kk],r), {}) : v, 2).
Related tools
- Base64 Encoder / Decoder — Encode and decode Base64 strings and files. Client-side, safe for sensitive data.
- XML Formatter — Format, validate, and beautify XML documents.
- YAML ↔ JSON Converter — Convert between YAML and JSON formats with full fidelity.
- CSV to JSON Converter — Convert CSV files to JSON with proper quoting and escaping.
- JSON Diff — Compare two JSON objects structurally with field-by-field diff.
Related articles
- 4 min readJSON Minification — Remove Whitespace and Reduce Payload SizeMinifying JSON removes all whitespace and produces compact payloads for API responses and storage. Learn how to minify JSON in JavaScript, Python, and at the server level with...
- 4 min readJSON Parse Errors — SyntaxError, Common Causes, and Safe ParsingJSON.parse throws SyntaxError for any malformed input. Learn the most common JSON parse errors, how to debug them, safe parsing with try/catch, and handling partial/streaming...
- 4 min readJSON.stringify Options — replacer, space, and Circular Reference HandlingJSON.stringify accepts three arguments: value, replacer, and space. Learn how to use the replacer function to filter keys, the space parameter for pretty-printing, handle...
- 4 min readJSON5 Format — Comments, Trailing Commas, and Extended JSON SyntaxJSON5 extends JSON with JavaScript-style comments, trailing commas, unquoted keys, single-quoted strings, and hexadecimal numbers. Learn when to use JSON5 for config files and...
- 5 min readJSON Minifier — Compress JSON to Reduce API Payload SizeJSON minifier removes whitespace and newlines to shrink payload size. See how much you save and when minification actually matters for API performance.
- 5 min readJSON Beautifier — Format and Prettify JSON InstantlyA JSON beautifier adds proper indentation and line breaks to minified JSON, making it human-readable. Here's how JSON formatting works, common formatting options, and why...
Pillar
Part of Data & Format — JSON, YAML, XML, CSV, SQL, Markdown utilities.
Written and maintained by Mian Ali Khalid. Last updated 2026-05-13.