JSON Pretty Print
Pretty print JSON online with optimized formatting for console output, log files, and terminal displays. Add indentation, color syntax highlighting, and aligned brackets—make JSON readable in command-line tools and server logs.
Why Use JSON Pretty Print
Server logs, CLI tool output, and terminal debugging display JSON as compact strings—unreadable for diagnosing issues. Pretty printing transforms raw JSON into formatted output optimized for monospace fonts and terminal environments: aligned colons, consistent spacing, and optional ANSI color codes for terminal syntax highlighting. Unlike web-focused formatters, pretty printers optimize for console width (80-120 characters), avoid excessive line breaks, and support color output for bash/zsh terminals. Essential for debugging Node.js applications with console.log, formatting JSON responses in curl commands, or making Python script output human-readable.
- Terminal-optimized: Formatting designed for console width limits
- ANSI colors: Optional terminal syntax highlighting
- Configurable depth: Control nesting display for deep objects
- Compact mode: Balance readability vs vertical space
- Copy for CLI: Ready to paste into terminal or scripts
Step-by-Step Tutorial
- Copy JSON from curl response or application log
- Example:
{"status":"error","code":500,"details":{"message":"Database timeout","query":"SELECT * FROM users"}} - Paste into pretty printer
- Select output format: Terminal (ANSI colors) or Plain (no colors)
- Pretty printed output optimized for 80-character terminal width
- Copy and paste into terminal or add to bash script
Real-World Use Case
A DevOps engineer troubleshoots API failures in production logs. Application logs JSON error objects as single-line strings spanning 300+ characters. Errors scroll off screen, nested error details are invisible, and diagnosing issues requires decoding minified JSON mentally. They add a pretty print filter to log processing pipeline: logs are parsed, JSON fields are pretty printed with 2-space indent, and output includes ANSI colors for keys/values/types. Error logs now display structured readable JSON showing error code, message, and stack trace clearly. Mean time to diagnose drops from 15 minutes to 3 minutes per incident. The engineer shares the pretty print script with the team, improving debugging efficiency across all services.
Best Practices
- Use 2-space indent for terminal output (saves horizontal space)
- Enable ANSI colors when debugging in modern terminals
- Pipe curl JSON through pretty printer:
curl api.com | json-pp - Add pretty printing to Node.js console.log with JSON.stringify(obj, null, 2)
- For log files, use plain format (no colors) for text editor compatibility
Performance & Limits
- File size: Pretty prints JSON up to 50 MB
- Terminal width: Optimizes for 80-120 character displays
- Color output: ANSI 256-color support for modern terminals
- Processing speed: 1 MB formatted in under 200ms
- Depth control: Limit nesting display for deep structures
Common Mistakes to Avoid
- Using colors in log files: ANSI codes clutter text editors—use plain format
- Excessive indentation: 4+ spaces waste terminal width—use 2-space
- Not limiting depth: Deeply nested JSON overwhelms console—set max depth
- Ignoring terminal width: Format for 80-char if output shared via email/chat
Privacy and Data Handling
JSON pretty printing happens entirely in your browser using JavaScript—data never leaves your device. For production logs containing customer data, sanitize sensitive fields before pretty printing or use log masking tools that redact PII before formatting.
Frequently Asked Questions
What's the difference between pretty printing and formatting JSON?
Both add indentation and line breaks, but pretty printing optimizes for terminal/console display: constrained to 80-120 character width, uses ANSI color codes for syntax highlighting in terminals, offers compact mode balancing readability vs vertical space, and aligns output for monospace fonts. Web formatters optimize for code editors and browsers with unlimited width and HTML/CSS styling. Use pretty print for debugging in terminals, CI/CD logs, or command-line tools. Use web formatters for documentation, code review, or browser-based tools. Pretty print output looks clean in ssh sessions and terminal windows where color-coded keys/values aid quick visual parsing.
How do I pretty print JSON in the command line?
Multiple tools available: (1) Python: python -m json.tool input.json or cat file.json | python -m json.tool, (2) Node.js: install json globally npm install -g json then json < file.json, (3) jq: jq . file.json (most popular, includes color), (4) Pipe curl: curl api.com/data | jq . for pretty printed API responses. For permanent aliases, add to .bashrc: alias json='python -m json.tool' or alias jp='jq .'. jq offers most features: colors, filtering, querying, and works on Linux/Mac/Windows.
Can I pretty print JSON with custom indentation and colors?
Yes, most CLI tools support customization: jq uses --indent N for custom spacing, --color-output or -C forces colors, -M disables colors. Python json.tool uses --indent N. Node.js JSON.stringify: JSON.stringify(obj, null, N) where N is spaces. For custom color schemes, jq reads JQ_COLORS environment variable: export JQ_COLORS="1;90:0;39:0;39:0;39:0;32:1;39:1;39" (null:false:true:numbers:strings:arrays:objects). Create shell functions wrapping these for team-wide consistent formatting. Many developers maintain dotfiles with preferred JSON pretty print aliases and color schemes.
How do I integrate pretty printing into application logging?
Add pretty printing to development logging, keep compact for production. Node.js: use JSON.stringify(obj, null, 2) in console.log for local dev, minified for prod. Python: configure logging formatter with json library in dev, structured logging (no pretty print) in prod. For log aggregation (ELK, Splunk), send minified JSON (saves bandwidth), pretty print on retrieval/display. Compromise: pretty print errors only (failures need immediate readability), compact for info/debug (volume too high for formatting). Environment-based: const indent = process.env.NODE_ENV === 'development' ? 2 : 0 switches formatting based on environment.