X Xerobit

JSON Formatter & Minifier

Paste JSON, get it formatted and validated instantly. Switch to minified output to strip whitespace for production. Runs 100% in your browser — your data never hits our servers. Shows exact line and column on parse errors.

Shortcuts: Ctrl/⌘ + Enter format · Ctrl/⌘ + Shift + C copy

How to use the JSON Formatter

  1. Paste your JSON into the left textbox. Formatting begins automatically after you stop typing for 300ms.
  2. Choose your indent: 2 spaces (default), 4 spaces, tab, or minified (single line).
  3. Read the result in the right textbox. On parse errors, the status line shows exact line and column.
  4. 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:

"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:

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:

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

JSON types reference

TypeJSON syntaxJS equivalentNotes
string"hello"stringDouble quotes only. Escape \\, ", and control chars.
number42, 3.14numberNo hex, no octal, no NaN, no Infinity.
booleantrue, falsebooleanLowercase only. True is invalid JSON.
nullnullnullLowercase only. Represents intentional absence of value.
array[1, "a", true]ArrayOrdered. Can mix types. No trailing comma.
object{"key": value}ObjectUnordered 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

Related articles

Pillar

Part of Data & Format — JSON, YAML, XML, CSV, SQL, Markdown utilities.


Written and maintained by Mian Ali Khalid. Last updated 2026-05-13.