JSON Formatter & Validator

Paste JSON to pretty-print it with 2 spaces, 4 spaces or tabs, minify it for production, or sort every key alphabetically. The validator follows the JSON standard (RFC 8259) exactly and shows the line, column and a caret under the first error, with a plain-language explanation. It can also strip comments and trailing commas copied from config files, and it reports duplicate keys, depth and size. Nothing is uploaded.

Mode
Indentation

Input

136 characters

Output

Formatted JSON
{
  "name": "Ali Tools Express",
  "version": 3,
  "tags": [
    "json",
    "formatter"
  ],
  "settings": {
    "indent": 2,
    "sortKeys": false,
    "theme": null
  },
  "active": true
}
  • Output size: 191 B
  • Keys: 8
  • Objects: 2
  • Arrays: 1
  • Depth: 2

Checks

  • Pass Valid JSON (RFC 8259).

Runs entirely in your browser. Nothing you paste or open here is uploaded or stored.

How to use the JSON formatter

  1. Paste your JSON into the input box, or press Sample to try it.
  2. Choose Format or Minify. Format adds line breaks and indentation; Minify removes every unnecessary space.
  3. Pick the indentation: 2 spaces (the most common), 4 spaces or tabs.
  4. Turn on Sort keys to order every object’s keys from A to Z, which makes two files easy to compare.
  5. Keep “Fix comments and trailing commas” on if you paste from config files.
  6. Copy or download the result as a .json file.

If the JSON is invalid, the output panel shows the error instead: the line and column, what went wrong, and the line itself with a caret (^) under the problem.

How the validator works

The tool has its own parser instead of relying on the browser’s JSON.parse. Browsers report errors in different ways, and some only give a character offset. Reading the text character by character means every error can be described precisely and the same way in every browser. It follows RFC 8259:

  • objects use { } with double-quoted keys, arrays use [ ];
  • strings use double quotes and only these escapes: \" \\ \/ \b \f \n \r \t \uXXXX;
  • numbers have no leading zeros, no leading +, and no NaN or Infinity;
  • the only literal words are true, false and null.

Duplicate keys are recorded with their full path (for example $.settings.theme) so you can find them in large files.

Worked examples

Example 1: an API response on one line

Paste a minified response such as {"id":7,"tags":["a","b"],"owner":{"name":"Ana"}}. Format it with 2 spaces and nested objects become readable in seconds. The statistics line shows keys, objects, arrays and depth, which helps when you’re writing types or a schema for the response.

Example 2: a config file with comments

A tsconfig.json or VS Code settings file often contains // comments and a trailing comma after the last property. With the fix option on, both are removed (strings such as URLs containing // stay intact) and you get strict JSON that any parser accepts. A note under the output lists what was changed.

Example 3: finding a missing comma

Paste a hand-edited file where one line is missing its comma. The error appears as Line 14, column 3: unexpected character “ with the offending line shown beneath it. The parser stops at the first error, so fix that and the next one (if any) is shown.

Formatting vs minifying

Formatted JSON is for people: code reviews, documentation and debugging. Minified JSON is for machines: it removes whitespace and typically saves 10–30% before compression. With gzip or Brotli on the server, the difference shrinks further, so minify mainly for storage, query strings or embedded data.

Common mistakes

  • Single quotes. {'a': 1} is JavaScript, not JSON. Use double quotes.
  • Unquoted keys. {a: 1} fails; write {"a": 1}.
  • Comments in production JSON. Many parsers reject them; strip them before shipping.
  • Large numbers. JSON allows any size of number, but JavaScript loses precision above 2⁵³. Send IDs as strings.
  • Pasting smart quotes. Word processors replace " with “ ”, which JSON doesn’t accept.

Frequently asked questions

Why does my JSON fail when JavaScript accepts it?

JSON is stricter than JavaScript object syntax. Keys must be in double quotes, strings can't use single quotes, trailing commas and comments aren't allowed, and values like undefined, NaN or functions don't exist in JSON. The error message points to the first character that breaks these rules.

Is it safe to paste API responses or config files here?

Yes. The formatter runs entirely in your browser with no server involved, so your data never leaves your device. Still, treat secrets such as API keys with care wherever you paste them.

What does “fix comments and trailing commas” do?

Many config formats (JSONC, used by VS Code and TypeScript) allow comments and trailing commas. This option removes them before validating, without touching the contents of strings, so you can convert those files into strict JSON.

What happens with duplicate keys?

The JSON standard says names should be unique but doesn't forbid duplicates. Most parsers keep the last value. The validator keeps the last value too and lists every duplicate so you can decide which one you meant.

Can I minify JSON as well as format it?

Yes. Choose minify to remove all whitespace, which makes payloads smaller. Formatting with two-space indentation is easier to read and review.

Sources