Before I save to a .json file the string from the dictionary will equal a normal string but after I save and then load from that file the value from the dictionary will not be considered equal. I have tested with integer values and those do work but the strings will not for me. How do I make them equal each other?
Code:
import json
details = {'apple': 2, 'orange': 3, 'cat': 'tree'}
print("details['cat'] is 'tree':", details['cat'] is 'tree')
with open("example.json", "w") as outfile:
json.dump(details, outfile)
outfile.close()
with open("example.json") as json_file:
loaded_details = json.load(json_file)
json_file.close()
print("loaded_details['cat'] is 'tree':", loaded_details['cat'] is 'tree')
Output:
details['cat'] is 'tree': True
loaded_details['cat'] is 'tree': False