DEV Community

BHUVANESH M
BHUVANESH M

Posted on β€’ Edited on

1 2

Python's Hidden Gem for JSON Indentation

Still pasting JSON into websites to read it? Python gives you a cleaner, offline way in one line.

πŸ“¦ The Built-in Way β€” No Extra Installs

Python ships with a powerful toolset for handling JSON.
Here's how to pretty-print JSON instantly:

import json

with open("data.json") as f:
    data = json.load(f)
    print(json.dumps(data, indent=4))
Enter fullscreen mode Exit fullscreen mode

βœ… Indented
βœ… Readable
βœ… Offline & fast

πŸ”€ Bonus: From String Instead of File

json_str = '{"name":"name","skills":["skill1","skill2"]}'
print(json.dumps(json.loads(json_str), indent=2))
Enter fullscreen mode Exit fullscreen mode

🧠 Real Uses

  • Debug API responses
  • View config files
  • Log structured data beautifully

🧼 Clean Trick: Sorting Keys Too

print(json.dumps(data, indent=4, sort_keys=True))
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Sometimes the most powerful tools are the ones built in.


πŸ“– For more tips and tricks in Python 🐍, check out

Packed with hidden gems, Python's underrated features and modules are real game-changers when it comes to writing clean and efficient code.


Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

AWS Security LIVE!

Join AWS Security LIVE! streaming from AWS Partner Summit Hamburg

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️