DevFormatter

JSON Beautifier

Instantly beautify compact or minified JSON with proper indentation — no server, no signup.

This is the same tool as our JSON Formatter — beautify, format, and pretty print all mean the same thing: adding indentation so JSON is human-readable.
Open JSON Formatter →

What is a JSON Beautifier?

A JSON beautifier takes compact or minified JSON and reformats it with consistent indentation and line breaks so the structure is immediately clear. The terms JSON formatter, JSON pretty printer, and JSON indenter all refer to the same operation.

Under the hood, two native browser APIs do all the work:

  1. JSON.parse(input) — validates and parses the raw string into a JavaScript object. If the JSON is invalid, an error is thrown with the problem location.
  2. JSON.stringify(parsed, null, indent) — serializes the object back to a string with the chosen indent depth (2 spaces, 4 spaces, or a tab character).

The result is functionally identical JSON — same data, same values — just formatted for human eyes.

Before & After

Input (minified):

{"name":"Alice","age":30,"roles":["admin","user"],"address":{"city":"London","zip":"EC1A 1BB"}}

Output (beautified, 2-space indent):

{
  "name": "Alice",
  "age": 30,
  "roles": [
    "admin",
    "user"
  ],
  "address": {
    "city": "London",
    "zip": "EC1A 1BB"
  }
}

Indentation options

  • 2 spaces — the default; matches Prettier, ESLint, and most JavaScript/TypeScript conventions.
  • 4 spaces — preferred in Python (indent=4), Java, and C# projects.
  • Tab — useful when pasting into editors that remap tab width to match project settings, so the visual indentation adapts automatically.

JSON Beautifier at a Glance

Every feature available in the JSON Formatter — not just beautification.

Feature What it does Example / note
Beautify Adds indentation and newlines for human readability {"a":1} → multi-line with indent
Minify Strips all whitespace to produce the smallest output Saves bandwidth; reduces localStorage usage
Sort Keys Sorts all object keys alphabetically at every depth Reduces git diff noise; aids comparison
Validate Reports the exact line and column of any syntax error Catches trailing commas, unquoted keys, etc.
Convert to YAML Converts valid JSON to equivalent YAML syntax Useful for config files in k8s, CI/CD pipelines
Detect Duplicates Finds duplicate object keys that cause silent data loss Last-write-wins in most parsers; dangerous in APIs

When to Beautify JSON

Common developer scenarios where proper indentation saves significant debugging time.

🔍 Debugging API responses

REST and GraphQL APIs often return minified JSON in production. Beautifying the response makes it easy to verify field names, check nesting, and spot missing or unexpected values without mentally parsing a wall of text.

👀 Code review

JSON fixture files, mock data, and configuration checked into source control should always be beautified before committing. Reviewers can read structured output at a glance, and git diffs stay meaningful rather than showing one-line blobs.

📋 Log inspection

Application logs that emit JSON events (structured logging) are often single-line per event for efficiency. Beautifying individual log entries lets you trace the full event context — timestamps, trace IDs, nested error objects — without a dedicated log viewer.

⚙️ Config file editing

JSON is widely used for configuration files (package.json, tsconfig.json, .eslintrc, AWS IAM policies). Beautifying before editing reduces the chance of introducing syntax errors and makes it obvious where a new key should be inserted.

Tips & Tricks

Non-obvious ways to get more out of the JSON Formatter.

Sort Keys before git diff

If two JSON objects contain the same keys but in different orders, a plain diff shows every line as changed. Clicking Sort Keys on both before comparing normalises key order so only genuinely changed values appear in the diff.

Minify before localStorage

Browsers cap localStorage at 5–10 MB per origin. Minifying JSON before storing it can cut size by 20–40% depending on the original indentation depth. Run Minify in the JSON Formatter, then copy the output into your storage call.

Tab indent for editor-aware paste

When you paste beautified JSON into VS Code or IntelliJ and the editor has a different indent size, tab-indented JSON re-renders at whatever tab width the editor is configured for — so the visual structure stays correct without extra reformatting.

Detect Duplicates catches silent corruption

Duplicate object keys are technically invalid per RFC 8259 but most parsers accept them silently — keeping the last value and discarding earlier ones. The Remove Duplicates tool surfaces all duplicate keys so you can decide which value to keep.

Convert to YAML for k8s / CI config

Kubernetes manifests, GitHub Actions workflows, and Docker Compose files all use YAML. If you draft configuration as JSON (which has better editor autocomplete for schemas), use Convert to YAML to get the final file format without manual rewriting.

Beautify validates in the same step

The formatter validates JSON before beautifying. If your JSON has a syntax error — a missing quote, a trailing comma, or an unescaped character — the tool reports the exact line and column before attempting to format. You get validation for free every time you beautify.

Code Examples

How to beautify JSON programmatically in common environments.

Node.js

const raw = '{"name":"Alice","roles":["admin","user"]}';
const pretty = JSON.stringify(JSON.parse(raw), null, 2);
console.log(pretty);
// Output:
// {
//   "name": "Alice",
//   "roles": [
//     "admin",
//     "user"
//   ]
// }

Pass '\t' as the third argument instead of 2 for tab indentation. No npm packages required.

Python

import json

raw = '{"name":"Alice","roles":["admin","user"]}'
pretty = json.dumps(json.loads(raw), indent=2)
print(pretty)
# Output:
# {
#   "name": "Alice",
#   "roles": [
#     "admin",
#     "user"
#   ]
# }

Add sort_keys=True to json.dumps() to sort object keys alphabetically. The json module is part of the Python standard library — no pip install needed.

Command Line (jq / Python)

# Using jq (install: brew install jq / apt install jq)
echo '{"name":"Alice","roles":["admin","user"]}' | jq .

# Using Python's built-in json.tool module (no install needed)
cat file.json | python3 -m json.tool

# Save the result to a new file
cat file.json | python3 -m json.tool > file-pretty.json

# jq with 4-space indent
cat file.json | jq --indent 4 .

jq is the fastest option and handles large files efficiently. python3 -m json.tool works without any installation on any machine that has Python 3.

Frequently Asked Questions

What is a JSON beautifier?
A JSON beautifier takes compact or minified JSON and adds indentation and line breaks so the structure is easy for humans to read. It is also called a JSON formatter, JSON pretty printer, or JSON indenter — they all perform the same operation. Under the hood, the tool calls JSON.parse() to validate and parse the input, then JSON.stringify(parsed, null, indent) to serialize it back with the chosen indentation. The result is functionally identical JSON that is far easier to read and debug.
What is the difference between beautify and minify?
Beautify adds whitespace and indentation for human readability — the output is larger in bytes but easy for developers to scan. Minify removes all unnecessary whitespace, comments, and newlines to produce the smallest possible output, which is useful before network transfer or production deployment where every byte counts. Both operations produce semantically identical JSON data; only the formatting differs. A good workflow is to keep beautified JSON in source control and minify automatically as part of the build or deployment pipeline.
Is my JSON data sent to a server?
No. All processing runs entirely in your browser using JavaScript. Your data never leaves your machine and no account or login is required. The DevFormatter JSON Beautifier uses the browser's native JSON.parse() and JSON.stringify() APIs — there is no server call, no telemetry on your JSON content, and no third-party data sharing. This makes it safe to paste API keys, tokens, or other sensitive configuration data for quick inspection, though best practice is to rotate any credentials that have been exposed.
Can I choose the indentation style?
Yes. The JSON Formatter supports 2-space, 4-space, and tab indentation. Select your preferred style from the indent selector in the toolbar before clicking Beautify. Two spaces is the most common convention in JavaScript and TypeScript projects (Prettier default). Four spaces matches Python's json.dumps(indent=4) default and is common in Java and C# codebases. Tab indentation is useful when pasting into editors that remap tab width to match project settings — the visual width adapts automatically.
What is the difference between JSON beautifier and JSON validator?
A beautifier reformats valid JSON for readability. A validator checks whether the JSON is syntactically correct and reports the exact line and column of any error. The DevFormatter JSON Formatter does both — it validates first and only beautifies if the input is valid. If your JSON has an error such as a trailing comma, an unquoted key, or a missing closing bracket, the tool reports the precise location of the problem before attempting to beautify. This means you get validation and formatting in one step.
What is the difference between JSON beautifier and JSON formatter?
There is no functional difference — JSON beautifier and JSON formatter are two names for the same operation: adding indentation and line breaks to make JSON human-readable. The word "beautifier" is common in front-end tooling communities (similar to CSS beautifier, HTML beautifier), while "formatter" is preferred in editor integrations like VS Code and JetBrains IDEs. Other synonyms include JSON pretty printer, JSON indenter, and JSON pretty-print. All refer to the same JSON.stringify(parsed, null, indent) transformation.
What is JSON pretty print?
JSON pretty print is another term for JSON beautification — the process of adding whitespace, newlines, and indentation to compact JSON so it is easy for humans to read. The term originates from Lisp and Python traditions where "pprint" (pretty-print) means rendering a data structure in a visually structured format. In Python, json.dumps(data, indent=2) is the built-in pretty-print function. In JavaScript, JSON.stringify(data, null, 2) performs the same operation. All three terms — pretty print, beautify, and format — produce identical output.
How do I beautify JSON in VS Code?
In VS Code, open your JSON file, then press Shift+Alt+F on Windows/Linux or Shift+Option+F on Mac to format the document using the built-in JSON language server. Alternatively, right-click anywhere in the file and choose Format Document. If VS Code prompts you to select a formatter, choose the built-in JSON formatter or Prettier if you have that extension installed. You can also set "editor.formatOnSave": true in settings.json to format automatically every time you save a .json file.
How do I beautify JSON on the command line?
The easiest command-line tool is jq — install it with brew install jq on macOS or apt install jq on Debian/Ubuntu. Run: cat file.json | jq . to pretty-print with 2-space indent, or jq --indent 4 . for 4 spaces. If jq is not installed, Python's built-in module works without any install: python3 -m json.tool file.json. To save the result: cat file.json | python3 -m json.tool > file-pretty.json.
How do I beautify JSON in Python?
Use Python's built-in json module: import json; print(json.dumps(json.loads(raw), indent=2)). The indent parameter accepts any integer — 2 and 4 are most common. To read from a file: with open('file.json') as f: data = json.load(f), then print(json.dumps(data, indent=2)). Add sort_keys=True to sort keys alphabetically. No third-party library is required — the json module ships with Python 2.6 and later.
How do I beautify JSON in Node.js?
Use JSON.stringify with the third argument as the indent level: const pretty = JSON.stringify(JSON.parse(rawString), null, 2). The second argument (null) is a replacer — pass null to include all keys. Pass '\t' as the third argument for tab indentation. To read from a file: const data = JSON.parse(fs.readFileSync('file.json', 'utf8')), then fs.writeFileSync('out.json', JSON.stringify(data, null, 2)). No npm packages are needed — this is built into every Node.js version.
What is the fastest way to beautify a large JSON file?
For files up to a few megabytes, any browser-based tool or jq on the command line is fast enough. For very large files (10 MB+), jq is the fastest option — it streams JSON without loading the entire structure into memory. Run: jq . large-file.json > large-file-pretty.json. For files in the gigabyte range, consider json_reformat (part of yajl) or fx (a terminal JSON viewer). Browser-based tools handle files up to around 5 MB comfortably, but for larger files the command-line approach is recommended.

Related Tools

Other free developer tools available on DevFormatter.