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