jsonformattertutorialbeautifierpretty-print

How to Format JSON Online — The Complete Guide

·7 min read·Tool Guides

What is JSON Formatting?

JSON formatting (also called beautifying or pretty-printing) adds proper indentation and line breaks to compact JSON, making it easy for humans to read and understand.

A minified API response like this:

json
{"user":{"id":1,"name":"Ravi Mehta","email":"ravi@example.com","active":true,"tags":["developer","admin"]}}

Becomes this after formatting with 2-space indent:

json
{
  "user": {
    "id": 1,
    "name": "Ravi Mehta",
    "email": "ravi@example.com",
    "active": true,
    "tags": [
      "developer",
      "admin"
    ]
  }
}

The data is identical — only the whitespace changes. Formatted JSON is the starting point for debugging, documentation, and code review.

How to Format JSON in One Click

  1. Open the JSONKit Formatter at /json-formatter
  2. Paste your raw or minified JSON into the left input panel (or drag a .json file onto it)
  3. Click Format or press Ctrl + Enter on Windows, Cmd + Enter on Mac
  4. Formatted JSON appears in the right output panel instantly
  5. Click Copy to copy to clipboard, or Download to save as output.json

The formatter validates your JSON as you type. A red bar at the bottom shows any syntax error with its exact line and column number before you even click Format.

Indentation Options

Use the 2 / 3 / 4 tab selector in the toolbar to choose how many spaces to use per indent level:

  • 2 spaces — most common; used by JavaScript, Node.js, most REST APIs, JSON Schema, and GitHub
  • 3 spaces — sometimes preferred in Ruby and some Python projects
  • 4 spaces — common in Java, C#, and Python PEP-8 style

Changing the indent while formatted output is already visible immediately reformats the JSON — no need to click Format again.

Sort Keys

Click Sort Keys to alphabetically sort all object keys at every nesting level of the JSON. This is useful when:

  • Diffing two JSON objects where key order varies between versions
  • Producing deterministic output for hashing or caching comparisons
  • Writing documentation where alphabetical order is easier to scan
  • Normalizing configs from different environments before comparing

Sort Keys is recursive — every nested object is sorted, not just the root level.

Minify from the Same Page

Click Minify to strip all whitespace and compress your JSON to a single line. Minification typically reduces JSON size by 20–50% depending on indentation depth. You can switch between Format, Sort Keys, and Minify on the same input without re-pasting.

File Upload and Download

Upload: Click the Upload button or drag a .json or .txt file directly onto the input panel. Files load instantly and validation runs immediately. There is no file size limit — files up to several megabytes work fine.

Download: Click Download to save the current output as a file named output.json. Useful when you want to replace a file on disk or send it as an attachment.

All file operations run entirely in your browser — no file is ever sent to a server.

Format JSON in Your Code

To format JSON programmatically, pass a non-zero indent to the stringify/encode function:

JavaScript:

javascript
const formatted = JSON.stringify(obj, null, 2); // 2-space indent
console.log(formatted);

Python:

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

Command line (Python):

bash
# Pretty-print a JSON file to stdout
python3 -m json.tool data.json

# Or pipe from curl
curl -s https://api.example.com/users | python3 -m json.tool

jq (fastest CLI formatter):

bash
# Install: brew install jq / apt install jq
jq . data.json        # format
jq -c . data.json     # minify
jq 'keys' data.json   # list root keys

Why Formatting Matters for API Development

  • Debugging — a minified 10 KB API response is unreadable; formatted it reveals the structure in seconds
  • Code review — comparing two JSON payloads is only possible when both are consistently formatted
  • Documentation — formatted JSON examples in README files and API docs are far more readable
  • Onboarding — new team members understand data shapes faster from formatted examples
  • Error isolation — a formatted response makes it easy to spot missing fields, wrong types, or unexpected nesting

Session Auto-Save

Your last JSON input is automatically saved to localStorage. Close the tab and come back later — your JSON is still there. Click Clear to wipe the saved session. Nothing is ever sent to any server.

Try JSON Formatter

Format and beautify JSON instantly. Syntax highlighting, error detection and collapsible tree view.