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:

  • 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, and Infinity are not valid JSON. Use null.

"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 undefined or NaN. 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.
  • null vs 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

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).

Pillar

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