How to Pretty-Print and Format JSON
JSON Formatting
When to Format JSON
Pretty-print JSON when reading API responses, reviewing config files, debugging webhook payloads, or preparing documentation examples from minified logs. Switch to tree view in Tool Settings to explore nested structures interactively.
Real-World Examples
Minified: {"id":1,"name":"Ada","active":true}
Formatted with indentation for readable nested objects and arrays
Log output from CloudWatch, Datadog, or browser network tabs pasted for inspection
Common Mistakes
- Pasting JSON with trailing commas (invalid in strict JSON)
- Confusing JSON with JavaScript object literals (unquoted keys, single quotes, comments)
- Formatting extremely large payloads in browser tabs without pagination
Edge Cases
- Duplicate keys — parsers typically keep the last value
- Very deep nesting can be hard to read even when formatted
- Numbers beyond safe integer range may lose precision in JavaScript
Performance Considerations
Formatting multi-megabyte JSON can freeze the browser tab. For huge files, use streaming CLI tools like jq instead.
Developer Tips
- CLI:
jq . file.jsonfor terminal formatting - Validate JSON before committing config files to version control
- Sort keys in documentation examples for stable diffs
Frequently asked questions
Why does my JSON fail to format?
Strict JSON does not allow comments, trailing commas, or single-quoted strings. Validate syntax at the reported error location.
Does formatting change the data?
No. Pretty-printing only changes whitespace — parsed values remain identical.
Can I format JSON with tabs instead of spaces?
Yes. In Tool Settings, choose indentation of 2 spaces, 4 spaces, or tab. The default remains 2 spaces.
Can I explore JSON as a tree instead of formatted text?
Yes. Choose Tree view in Tool Settings to browse nested objects and arrays with expandable nodes.