How to pretty print JSON with indentation in Python

1 Answer

0 votes
import json 
   
js = '[{"id":1,"Name":"Tom","password":"123456"},'\
     '{"id":2,"Name":"Amelia","password":"890123"},'\
     '{"id":3,"Name":"Audrey","password":"190364"}]'  

json_object = json.loads(js) 

print(json.dumps(json_object, indent = 2)) 
   
    
            
       
'''
run:
   
[
  {
    "id": 1,
    "Name": "Tom",
    "password": "123456"
  },
  {
    "id": 2,
    "Name": "Amelia",
    "password": "890123"
  },
  {
    "id": 3,
    "Name": "Audrey",
    "password": "190364"
  }
]
   

 



answered May 13, 2020 by avibootz

Related questions

3 answers 235 views
1 answer 160 views
1 answer 124 views
1 answer 146 views
1 answer 143 views
1 answer 161 views
...