1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5
6print(data)
1import json
2
3data = {"key": "value"}
4
5with open('data.json', 'w') as jsonfile:
6 json.dump(data, jsonfile)
7
1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5print(data)
6
7flx = json.dumps(data, ensure_ascii=False, indent=4)
8print(flx)
1import json
2
3#reading
4with open(file_name, 'r') as f:
5 data = json.load(f)
6
7#writing
8with open(file_name, 'w') as f:
9 json.dump(data, f) #use indent to make easyer to read eg. indent = 4
1import json
2
3with open('data.txt') as json_file:
4 data = json.load(json_file)
5 for p in data['people']:
6 print('Name: ' + p['name'])
7 print('Website: ' + p['website'])
8 print('From: ' + p['from'])
9 print('')
10