#Write an object

contents = {"aa": 12, "bb": 21}
with open("myfile2.txt", "w+") as file:
    file.write(json.dumps(contents))

#Read an object

with open('myfile2.txt', "r+") as file:
    contents = json.load(file)
print(contents)
Comments