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))
β
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))
π§ 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))
π‘ 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.
Top comments (0)