How to print dictionary as JSON sorted by key to in Python

1 Answer

0 votes
import json

dict = {"name": "R2D2", "code":"Python", "age": 60}

print(json.dumps(dict, sort_keys=True, indent=4))



'''
run:

{
    "age": 60,
    "code": "Python",
    "name": "R2D2"
}
 
'''

 



answered Sep 20, 2021 by avibootz

Related questions

1 answer 137 views
2 answers 189 views
2 answers 174 views
1 answer 169 views
1 answer 157 views
1 answer 162 views
...