pretty json python

Do you want to know the details about “pretty json python”. If yes, you’re in the correct article.

pretty json python


import json

json_data="["ID":10,"Name":"Pankaj","Role":"CEO"," \
            '"ID":20,"Name":"David Lee","Role":"Editor"]'

json_object = json.loads(json_data)

json_formatted_str = json.dumps(json_object, indent=2)

print(json_formatted_str)
import json

# alphabetic dictionary
json_data = hex(k): chr(k) for k in range(ord('a'), ord('z') + 1)
# to file
with open("my_json.json", "w") as file:
    json.dump(json_data, file, indent=4, sort_keys=True)
print(json.dumps(dict, indent=4))
import requests
import json
r = requests.get('http://server.com/api/2/....')
pretty_json = json.loads(r.text)
print (json.dumps(pretty_json, indent=2))
json.dumps(x, indent=4)

Final Thoughts

I hope this post helps you to know about “pretty json python”. If you have any questions regarding this tutorial please let us know via the comment section. Share this post with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment