I have a dictionary of dictionaries in Python which looks like this:
{
"Europe": {
"France": (10,5),
"Germany": (15,5),
"Italy": (5,15),
},
"North-America": {
"USA": (20,0),
"CANADA": (12,4),
"MEXICO": (14,8),
},
}
I want to save the dictionary in a JSON file to get the data when I need it. I do that store like this:
with open(filename, 'a') as jsonfile:
json.dump(dictionary, jsonfile)
The problem comes now. When I try to read the stored json dictionary I get same Error like this: Python json.loads shows ValueError: Extra data
The answer in that post is just to store the different dicts in a list and dumps all of them. But I dont understand how to do it if they are nested and they are created dynamically.
The way I read the json is this:
jsonFile = open(filename)
data = json.loads(jsonFile)
jsonFile.close()
return data
In resume. I need to load the dictionary from the json file to a dictionary in python. How can I achieve that?