🧩

JSON Formatter

Format, validate, minify, or sort JSON data with configurable indentation. Instantly check for syntax errors, view node count and nesting depth — free, no sign-up required.

Mode

Indentation

Input JSON

Output

Explore This Tool in Context

JSON Formatter is part of the Developer collection. If you want a broader view of similar workflows, open the Developer category page or browse all QuickTools categories.

Common next steps after this tool include QR Code Generator, Base64 Encoder / Decoder and UUID Generator.

What Is the JSON Formatter?

JSON (JavaScript Object Notation) is the most widely used data-interchange format on the web. It is human-readable but often arrives minified or incorrectly indented, making it hard to audit or debug. This tool parses any JSON input and lets you format, minify, validate, or sort keys in one click — with live statistics including line count, character count, total node count, and maximum nesting depth.

All processing happens server-side via a stateless API. Nothing is stored or logged. The formatted output can be copied to the clipboard or downloaded as a .json file.

How to Use This Tool

  1. Paste your JSON into the Input JSON box.
  2. Select a mode: Format, Minify, Validate, or Sort Keys.
  3. For Format and Sort, pick an indentation style: 2 spaces, 4 spaces, or tabs.
  4. Click the action button. Any syntax error is highlighted with the exact message from the parser.
  5. Copy the result or download it as formatted.json.

The Four Modes Explained

Format (Pretty-Print)

Parses the JSON and re-serialises it with consistent indentation. Ideal for reading API responses, reviewing configuration files, or committing readable JSON to version control.

Minify

Strips all whitespace characters (spaces, tabs, newlines) to produce the shortest possible valid JSON string. Use this before embedding JSON in a JavaScript bundle, HTTP request body, or database column to save bytes.

Validate

Parses the input and returns the formatted result if valid, or the exact syntax-error message (with position) if not. Great for catching trailing commas, unquoted keys, or single-quoted strings that are common mistakes.

Sort Keys

Recursively sorts all object keys alphabetically at every nesting level. This creates deterministic output useful for diffing two JSON objects, normalising API fixtures, or making version-control diffs easier to read.

JSON Syntax Quick Reference

TypeExampleNotes
String"hello world"Must use double quotes
Number42 / 3.14 / -7 / 1e3No quotes, no leading zeros
Booleantrue / falseLowercase only
NullnullLowercase only
Array[1, "two", true]Ordered, comma-separated
Object{"key": "value"}String keys, comma-separated pairs

Real-World Examples

REST API Response

{
  "status": "ok",
  "user": {
    "id": 42,
    "name": "Alice",
    "roles": ["admin", "editor"]
  }
}

Format API responses before reading; minify before putting them in cache.

package.json (Node.js)

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc",
    "start": "node dist/index.js"
  }
}

Validate package.json after manual edits to catch missing commas or mismatched braces.

Minified Payload (before HTTP POST)

{"userId":42,"action":"purchase","items":[{"id":7,"qty":2}]}

Minify JSON payloads to reduce HTTP body size and speed up requests.

How JSON Formatting Works

Under the hood the tool calls JSON.parse() on the raw input. If parsing fails, the native error message (which includes the character offset) is returned immediately. If it succeeds, the parsed JavaScript value is passed to JSON.stringify(value, null, indent) — where indent is 2, 4, or a tab character.

For Sort Keys, the parsed object is recursively traversed and its keys reinserted in alphabetical order before re-serialising. For Minify, JSON.stringify(value) is called without an indent argument, which produces compact output. Statistics (line count, node count, max depth) are computed in a single O(n) tree traversal.

Frequently Asked Questions

What is the difference between Format and Validate?

Both parse the JSON, so both detect errors. Format produces pretty-printed output; Validate also produces formatted output. In practice they behave identically — Validate mode is labelled to help users whose goal is only to check correctness rather than edit the output.

Why does my JSON fail even though it looks correct?

Common pitfalls: trailing commas after the last array element or object property (not allowed in JSON, only in JavaScript); single-quoted strings (JSON requires double quotes); unquoted property keys; and comments (// or /* */ are not part of the JSON standard). The error message includes the exact character offset.

What does "node count" mean?

Every value in the JSON tree counts as one node — each string, number, boolean, null, array, and object. A node count of 10 means the document contains 10 distinct values. This is useful for estimating document complexity.

What is "max depth"?

Max depth is the number of nesting levels from the root to the deepest child. A flat object like {"a": 1} has depth 1. An object inside an array inside another object has depth 3. Very deep nesting (> 20) can cause stack overflows in some parsers.

Does Sort Keys affect array order?

No. JSON arrays are ordered sequences, so element order is preserved exactly. Only object keys are sorted — objects are unordered by the JSON specification, so sorting is safe.

Can I format very large JSON files?

The tool handles typical payloads (up to a few megabytes) well. For very large files (10 MB+) you may hit request size limits. In those cases use a command-line tool: jq . file.json or python -m json.tool file.json.

Is JSONC (JSON with comments) supported?

Not directly — JSONC is not standard JSON. Strip comments first (e.g. with the "Strip JSON Comments" npm package), then paste the result here.

Related Tools

More in Developer

View category hub →