Program - Sort JSON keys in Python and write it into a file


Topic: Program - Sort JSON keys in Python and write it into a file

Solution

import json
sampleJson = {"id" : 1, "name" : "value2", "age" : 29}
with open("sampleJson.json", "w") as write_file:
    json.dump(sampleJson, write_file, indent=4, sort_keys=True)
print("Done writing JSON data into a file")



List all Python Programs