I have saved a dictionary as json to re-use later across a number of areas.
The dictionary structure is:
dict = {
1: 'Name',
2: 'Name2',
3: 'Name3'
}
I have saved it as so:
with open('fpath', 'w') as out :
json.dump(dict, out)
When I am reading it back in, though, it reads the dictionary keys as strings, not ints, as follows:
with open('fpath', 'r') as inf :
dict = json.load(inf)
print (dict)
dict = {
'1': 'Name',
'2': 'Name2',
'3': 'Name3'
}
This makes it so I can't use it as needed, for example to map it to a pandas dataframe column.
How do I save the dictionary so that the keys are saved and read back in as ints, not strings?