Skip to main content
Back to Tools

JSON Formatter

Format, beautify, and validate JSON with customizable indentation. Paste raw JSON, pick 2-space, 4-space, or tab indent, and get a clean readable result instantly.

TL;DR. Paste any JSON string into the input box, choose your indentation style, and click Format. The tool runs JSON.parse() to validate the input and JSON.stringify(value, null, indent) to re-serialise it with consistent whitespace. If the JSON is invalid, the exact error message and character position appear so you can fix the syntax. Click Minify to strip all whitespace for APIs or hashing. Everything runs in your browser - no data leaves your machine.

How to use the JSON formatter

  1. Paste your JSON. Copy a response from an API, a .json config file, or a minified blob from a network request and paste it into the input box. The tool accepts any valid JSON value: an object { }, array [ ], string, number, boolean, or null.
  2. Choose indentation. Select 2 Spaces for compact diffs and APIs, 4 Spaces for Python or Java codebases, or Tabs if your editor convention requires it. All three produce spec-valid JSON.
  3. Click Format or Minify. Format adds indentation and newlines for readability. Minify removes all whitespace to produce the smallest possible string, useful for signature inputs, storage, or network payloads.
  4. Read the error if validation fails. JSON.parse() throws a SyntaxError with the exact position of the problem. Common fixes: remove trailing commas, replace single quotes with double quotes, quote unquoted keys, or delete a BOM character at the start.
  5. Copy the output. Click the Copy button to put the formatted or minified result on your clipboard. The line count and byte size are shown so you can track payload changes when switching indentation styles.

JSON syntax cheatsheet

The JSON spec (RFC 8259) is small but unforgiving. Every token below is exact - no deviation is allowed.

Token / RuleDetail
nullThe null value. Not the string "null", not 0, not false.
true / falseBoolean literals. Must be lowercase.
"string"Strings must use double quotes. Single quotes are not valid JSON.
\" \\Escaped double quote / escaped backslash inside a string.
\n \t \rNewline / tab / carriage return inside a string.
\uXXXXUnicode escape: any code point as 4 hex digits, e.g. \u00e9 = e with accent.
123 / 1.5e2Numbers: integers and floats. No NaN, no Infinity, no leading zeros.
[ ]Array. Items separated by commas. Trailing comma not allowed.
{ }Object. Key-value pairs, keys must be quoted strings.
ISO 8601JSON has no date type. Use "2026-04-20T12:00:00Z" strings by convention.
No commentsJSON forbids // and /* */ comments. Use a JSONC parser for config files.
No trailing ,{"a":1,} and [1,2,] are syntax errors. Remove trailing commas.

Common JSON errors and how to fix them

  • Trailing comma: {"a":1,} or [1,2,] — remove the comma after the last item. This is valid JavaScript but the JSON spec forbids it.
  • Single-quoted strings: {'name':'Jim'} — replace every ' with ". JSON requires double quotes on both keys and values.
  • Unquoted keys: {name:"Jim"} — quote the key: {"name":"Jim"}.
  • NaN or Infinity: These are valid JavaScript numbers but not valid JSON. Replace with null or a quoted string like "Infinity" before serialising.
  • BOM at start of file: Some Windows text editors prepend a UTF-8 byte-order mark (U+FEFF). JSON.parse() will throw immediately. Strip it by deleting the first invisible character.
  • Comments inside JSON: If your file has // or /* */ comments, it is JSONC (used by tsconfig.json, VS Code settings). Strip comments before passing to this tool, or use a JSONC-aware parser like jsonc-parser.

Frequently asked questions

What does a JSON formatter actually do?+
It parses the raw JSON string with JSON.parse() to verify it is valid, then re-serialises it with JSON.stringify(value, null, indent) using your chosen indentation. The result is structurally identical to the input but has consistent whitespace, sorted nothing (key order is preserved), and is easy to read in a code review or diff.
What is the difference between JSON, JSON5, and JSONC?+
Standard JSON (RFC 8259) allows no comments, no trailing commas, and requires double-quoted string keys. JSON5 is a superset that adds single quotes, trailing commas, comments, and unquoted keys. JSONC (JSON with Comments) adds // and /* */ comments. Most APIs and databases expect strict JSON. Config files like tsconfig.json and .vscode/settings.json use JSONC. This tool parses strict JSON only; strip comments before pasting JSONC.
Why does my JSON throw "Unexpected token" errors?+
The four most common causes: (1) trailing commas after the last array item or object property, which are valid in JavaScript but illegal in JSON; (2) single-quoted string keys or values instead of double quotes; (3) unquoted keys like {name: "Jim"} instead of {"name": "Jim"}; (4) a BOM (byte-order mark) at the very start of the file when copy-pasting from Windows editors. The error message will include the character position to help locate the issue.
When should I use 2-space, 4-space, or tab indentation?+
Use 2 spaces for config files and APIs where payload size matters slightly. Use 4 spaces when your codebase or language convention requires it (Python PEP 8, some Java projects). Use tabs when your editor is set to expand tabs to match team preference, or when the file will be read in environments where tab width is configurable. All three are valid JSON; the choice is purely cosmetic.
What is canonical JSON and why does indentation matter for hashing?+
Canonical JSON is a serialisation where keys are sorted lexicographically and no extra whitespace is added. If you compute an HMAC or SHA-256 over a JSON payload, any whitespace or key-order difference produces a completely different hash. For signature verification, always compare minified canonical forms, not pretty-printed versions. Use Minify here, then pass the output to your hash function.
Is there a size limit? What happens at 500 MB?+
JavaScript string.length is limited by the V8 heap, not by a hard spec limit, but browsers typically allow single strings up to 256 MB to 1 GB depending on the device. At around 500 MB, JSON.parse allocates a large object graph on top of the string, so total memory can spike to 3-5x the raw size. For files that large, use a streaming parser (like the Node.js stream-json package or jq on the command line) rather than a browser tool.

Related developer tools