DevToolsKit
How-To Guides
5 min read · March 20, 2026

How to Format JSON — Step-by-Step Guide

Formatting JSON makes unreadable API responses, log dumps, and config files easy to understand and debug. This guide shows you exactly how to format JSON — whether you use an online tool, command line, or code.

Why Format JSON?

Raw JSON from APIs often arrives minified — all on one line with no spacing. While valid, it's nearly impossible to read. Formatting adds indentation and line breaks so you can quickly spot structure, find values, and debug issues.

Before and After: JSON Formatting

Minified JSON (hard to read):

{"users":[{"id":1,"name":"Alice","role":"admin"},{"id":2,"name":"Bob","role":"user"}],"total":2}

Formatted JSON (easy to read):

{
  "users": [
    {
      "id": 1,
      "name": "Alice",
      "role": "admin"
    },
    {
      "id": 2,
      "name": "Bob",
      "role": "user"
    }
  ],
  "total": 2
}

How to Format JSON Online (Fastest Method)

  1. Copy your raw JSON from API response, log file, or config
  2. Open the DevToolsKit JSON Formatter
  3. Paste JSON into the input field
  4. Click "Format" to beautify with 2-space indentation
  5. Copy the formatted output or download as a .json file

Format JSON Now — Free

Beautify, minify, syntax highlight, copy and download — no signup required.

Open Tool

How to Minify JSON

Minifying removes all whitespace to reduce file size. Use minified JSON in production API responses and config files where readability doesn't matter. Click "Minify" in our JSON Formatter to compress formatted JSON to a single line.

Validate Before Formatting

If formatting fails, your JSON likely has syntax errors. Validate first to find the exact problem — trailing commas, single quotes, or unquoted keys are common culprits.

Validate JSON First

Find syntax errors with line numbers before formatting.

Open Tool

Format JSON in Code

JavaScript/Node.js:

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

Python:

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

Related Free Tools

JSON Formatter

Format, minify, and beautify JSON with syntax highlighting.

Open Tool

JSON Validator

Validate JSON syntax with detailed error messages and line numbers.

Open Tool

Frequently Asked Questions

What indentation should I use for JSON?+

2 spaces is the most common standard. Some teams use 4 spaces or tabs. JSON.stringify in JavaScript uses spaces by default with the third argument.

Can I format invalid JSON?+

No. The JSON must be syntactically valid first. Use a validator to fix errors, then format.

Related Articles