developerSeptember 17, 2026•2 min read•ToolsHub Editorial Team

How to Format and Beautify JSON: Indentation, Minification & Tools

Learn how to format, pretty-print, and minify JSON payloads for readable logs, fast API transfers, and clean debugging.

Share guide:X / TwitterLinkedIn
Related Online Tool

Try the JSON Formatter

Calculate your numbers instantly in your browser. Fast, free, no signup.

Open Tool

When APIs deliver JSON data over network connections, they typically send it minified—stripping all whitespace, newlines, and indentations to save bandwidth. While efficient for machines, reading a single 5,000-character line of compressed JSON is practically impossible for human developers.

Formatting (or "pretty-printing") JSON adds structured indentation and line breaks, transforming dense blobs into readable data trees.


2-Space vs 4-Space Indentation

The most common conventions for JSON formatting are:

  • 2 Spaces (Recommended): The de facto standard across modern web development, NPM packages, GitHub repositories, and cloud API schemas. It keeps deeply nested structures readable without excessive horizontal scrolling.
  • 4 Spaces: Traditional standard often preferred in Java, Python, or C++ backend systems.
  • Tabs: Ensures readers can customize indentation width in their own text editors.

How to Format JSON Programmatically

In JavaScript / Node.js

The native JSON.stringify method accepts an indentation parameter as its third argument:

const raw = '{"name":"John","city":"New York","active":true}';
const parsed = JSON.parse(raw);

// Pretty-print with 2 spaces
const formatted = JSON.stringify(parsed, null, 2);
console.log(formatted);

In Python

Using Python's built-in json module:

import json

data = {"name": "John", "city": "New York", "active": True}
formatted = json.dumps(data, indent=2)
print(formatted)

In Terminal via jq

If you use Linux, macOS, or WSL, the powerful jq utility formats streams effortlessly:

curl -s https://api.example.com/data | jq .

Minifying JSON for Production

When you are ready to transmit JSON payloads across networks or store them in database columns, minification removes unnecessary indentation bytes:

const minified = JSON.stringify(JSON.parse(formattedText));

This reduces network payload sizes by anywhere from 15% to 40%.


Format & Beautify in 1 Click

Need to inspect a messy JSON string right now without running a terminal command? Paste your text into our free JSON Formatter. You can format with 2 or 4 spaces, minify, and copy the clean output instantly without sending any data over the internet.

Frequently Asked Questions

How do I format minified JSON into readable JSON?

Paste your raw JSON into an online JSON formatter or use JavaScript's native JSON.stringify(JSON.parse(rawText), null, 2) to format it with 2-space indentation.

Does formatting or pretty-printing JSON change its data payload?

No. Pretty-printing only inserts non-semantic whitespace and line breaks for human readability. Any JSON parser treats compact and formatted JSON identically.

Why does my JSON formatter report an Unexpected token error?

JSON syntax requires double quotes around keys and string values, does not allow single quotes, trailing commas, or JavaScript comments. Removing these fixes most formatting errors.

AN

ToolsHub Editorial Team

Verified Author

Technical Architect & Lead Developer • ToolsHub Pro

Abdul Nabi is a senior software engineer and technical architect specializing in client-side Web APIs, high-performance browser computing, cryptographic validation, and privacy-first digital utility platforms. All guides on ToolsHub Pro are peer-reviewed for mathematical rigor and developer accuracy.

Published on ToolsHub Pro • 100% Client-Side Free Tools

Recommended Tools

Related Guides