Suppose that I have a dictionary dict = {"fadfafa": {"price": 5}}
in python. If I do json.dump(dict)
, then I will end up getting {{"fadfafa":"{\"price\" : 5}"}
in the json file. Is there any way to store it in the json file just as how it originally looks like dict = {"fadfafa": {"price": 5}}
? So a minimal working example would be:
dict = {"fadfafa": {"price": 5}}
with open('temp.json') as output_file:
json.dump(dict)
The problem with this output is that when I do
with open('temp.json') as input_file:
json.load(temp.json = object_pairs_hook = dict_raise_on_duplicates")
It reads back the object not as a dictionary of dictionary but one single dictionary with its value being a string.