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 117 views
2 answers 149 views
2 answers 139 views
1 answer 152 views
1 answer 122 views
1 answer 141 views
...