python write object to json file code example
Example 1: get json from file python
import json
with open('data.txt') as json_file:
data = json.load(json_file)
for p in data['people']:
print('Name: ' + p['name'])
print('Website: ' + p['website'])
print('From: ' + p['from'])
print('')
Example 2: write json pythonb
>>> jstr = json.dumps(data, ensure_ascii=False, indent=4)
>>> print(jstr)
{
"item": "Beer",
"cost": "£4.00"
}