How to Format JSON: Complete Guide for Developers (2026)

Published February 4, 2026 • 8 min read

JSON (JavaScript Object Notation) is everywhere in modern development. Whether you're working with APIs, configuration files, or data storage, you'll encounter JSON daily. But raw, minified JSON is nearly impossible to read. This guide covers everything you need to know about formatting JSON.

What is JSON Formatting?

JSON formatting (also called "pretty printing" or "beautifying") transforms compact, single-line JSON into human-readable, indented format. Compare these:

Minified (hard to read):

{"name":"Alice","age":30,"skills":["JavaScript","Python","Go"]}

Formatted (easy to read):

{
  "name": "Alice",
  "age": 30,
  "skills": [
    "JavaScript",
    "Python",
    "Go"
  ]
}

Why Format JSON?

How to Format JSON

1. Online Tools (Fastest)

Use a free online JSON formatter like our JSON formatter tool. Just paste your JSON and click Format. No installation, no signup.

2. Command Line

If you have Python installed:

echo '{"name":"Alice"}' | python -m json.tool

Or with jq (install via brew/apt):

echo '{"name":"Alice"}' | jq .

3. In Your Code

JavaScript/Node.js:

const formatted = JSON.stringify(data, null, 2);
console.log(formatted);

Python:

import json
formatted = json.dumps(data, indent=2)
print(formatted)

Go:

formatted, _ := json.MarshalIndent(data, "", "  ")
fmt.Println(string(formatted))

4. Code Editors

Common JSON Formatting Errors

1. Trailing Commas

// Invalid
{
  "name": "Alice",
  "age": 30,  ← trailing comma
}

JSON doesn't allow trailing commas. Remove them before formatting.

2. Unquoted Keys

// Invalid
{
  name: "Alice"  ← unquoted key
}

// Valid
{
  "name": "Alice"
}

3. Single Quotes

// Invalid
{'name': 'Alice'}

// Valid
{"name": "Alice"}

JSON requires double quotes. Single quotes are not valid.

JSON Minification

The opposite of formatting is minification — removing all whitespace to reduce file size. Use this for:

Try our JSON minifier to compress your JSON instantly.

Best Practices

  1. 2-space indentation: Standard across most projects
  2. Validate before formatting: Fix syntax errors first
  3. Use consistent formatting: Set up your editor to auto-format
  4. Never format in production: Keep production JSON minified
  5. Use .prettierrc: Configure Prettier for consistent formatting

Tools We Recommend

Conclusion

Formatting JSON is essential for developer productivity. Whether you use online tools, command-line utilities, or IDE shortcuts, pick the method that fits your workflow. For quick formatting without installation, try our free JSON formatter.

Try It Now

Format your JSON instantly with our free online JSON formatter. No signup, no installation, runs entirely in your browser.

Back to Blog