convert list of dictionaries to json file python code example
Example: write list of dictionaries to json python
def filewriter(line):
dictionary = {}
dictionary['name'] = line[0][0]
dictionary['item_to_buy'] = line[0][1]
dictionary['currency'] = line[0][2]
dictionary['league'] = line[0][3]
with open('logs.json', 'r+') as f:
if len(f.read()) == 0:
f.write(json.dumps(dictionary))
else:
f.write(',\n' + json.dumps(dictionary))
def retrieve():
with open('logs.json') as f:
g = json.load(f)
print(g[1]['name'])