How to Pretty Print JSON
James Reed
Infrastructure Engineer · Leapcell

Key Takeaways
- Pretty printing JSON makes data easier to read and debug.
- Multiple tools and languages offer built-in JSON formatting features.
- Online formatters and command-line utilities are quick options for pretty printing.
JSON (JavaScript Object Notation) is a widely used data format for storing and exchanging information between servers and web applications. However, JSON data is often transmitted as a single line or in a compact form, making it hard to read for humans. Pretty printing JSON means formatting it with indentation and line breaks, making it easier to understand and debug.
In this article, we will explore different ways to pretty print JSON using various programming languages and tools.
Why Pretty Print JSON?
Pretty printing is useful for:
- Debugging: Easily spot errors and understand the structure of your data.
- Documentation: Make JSON responses readable in documentation or logs.
- Presentation: Share readable data with colleagues or stakeholders.
Pretty Printing JSON in Python
Python provides built-in support for working with JSON through the json
module. Here’s how you can pretty print a JSON object:
import json data = { "name": "Alice", "age": 25, "city": "New York" } # Pretty print with indentation pretty_json = json.dumps(data, indent=4) print(pretty_json)
This will output:
{ "name": "Alice", "age": 25, "city": "New York" }
You can also pretty print JSON files from the command line:
python -m json.tool input.json
Pretty Printing JSON in JavaScript
JavaScript's JSON.stringify()
method can be used to pretty print JSON:
const data = { name: "Alice", age: 25, city: "New York" }; console.log(JSON.stringify(data, null, 2));
Here, the third argument specifies the number of spaces for indentation.
Pretty Printing JSON in Command Line (jq)
For quick formatting in the terminal, you can use tools like jq
:
jq . input.json
jq
automatically formats JSON with colors and indentation, making it easy to read large files.
Pretty Printing JSON Online
There are several free online tools where you can paste your JSON data to pretty print it:
These tools provide instant formatting and can also validate your JSON for errors.
Conclusion
Pretty printing JSON enhances readability and helps in debugging and sharing data. Whether you are working in Python, JavaScript, on the command line, or using online tools, there are multiple ways to format your JSON data neatly. Try the method that best fits your workflow!
FAQs
It improves readability and helps in debugging JSON data.
Use json.dumps(data, indent=4)
to format JSON with indentation.
Yes, you can use free online JSON formatter tools.
We are Leapcell, your top choice for hosting backend projects.
Leapcell is the Next-Gen Serverless Platform for Web Hosting, Async Tasks, and Redis:
Multi-Language Support
- Develop with Node.js, Python, Go, or Rust.
Deploy unlimited projects for free
- pay only for usage — no requests, no charges.
Unbeatable Cost Efficiency
- Pay-as-you-go with no idle charges.
- Example: $25 supports 6.94M requests at a 60ms average response time.
Streamlined Developer Experience
- Intuitive UI for effortless setup.
- Fully automated CI/CD pipelines and GitOps integration.
- Real-time metrics and logging for actionable insights.
Effortless Scalability and High Performance
- Auto-scaling to handle high concurrency with ease.
- Zero operational overhead — just focus on building.
Explore more in the Documentation!
Follow us on X: @LeapcellHQ