I got multiple dictionaries in json format 'some.json' looking like these
{
"my_dict" : {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
},
"my_dict2" : {
'key8': 'value8',
'key9': 'value9',
'key10': 'value10'
}
}
Both key and value are strings. I would like to export it to csv format vertically then read it back to json file. For example, when I add an item to my_dict on csv format then it would also be added on the json file.
Required output
my_dict
key1,value1
key2,value2
key3,value3
my_dict2
key8,value8
key9,value9
key10,value10
I got so far a solution, but the problem is, the name of the dictionaries are not written on the csv file so can't be read back to json file
import pandas as pd
with open('some.json') as f_input:
df = pd.read_json(f_input)
df = df.bfill(axis='columns')
df.iloc[:, 0].to_csv('some.csv', encoding='utf-8', header=False)