JSON Standards⏱️ 5 min readUpdated: 2026-08-19

How to Format & Pretty-Print JSON: Tools & Code Techniques

Learn how to format and pretty-print JSON online, in VS Code, with CLI tools like jq, and programmatically in Python and JavaScript.

Why Format JSON?

Raw API responses and log streams are typically compressed into dense single-line strings. Formatting adds indentation and line breaks, turning unreadable payloads into structured, reviewable code.

Programmatic Pretty-Printing

JavaScript (Node.js & Browser)

Use the third argument of JSON.stringify to specify indentation spacing:

const user = { id: 1, name: "Alice", active: true };

// Format with 2 spaces:
const pretty2 = JSON.stringify(user, null, 2);

// Format with 4 spaces:
const pretty4 = JSON.stringify(user, null, 4);

// Format with tabs:
const prettyTab = JSON.stringify(user, null, "\t");

Python

Pass the indent parameter to json.dumps():

import json

payload = {"status": "ok", "count": 42}
formatted = json.dumps(payload, indent=2)
print(formatted)

Command Line (jq)

# Pretty print a file
cat payload.json | jq .

# Pretty print API curl response
curl -s https://api.example.com/data | jq .

Try Related Tools on ToolNest