1import json
2
3with open('data.txt') as json_file:
4 data = json.load(json_file)
1# Python program to read
2# json file
3
4
5import json
6
7# Opening JSON file
8f = open('data.json',)
9
10# returns JSON object as
11# a dictionary
12data = json.load(f)
13
14# Iterating through the json
15# list
16for i in data['emp_details']:
17 print(i)
18
19# Closing file
20f.close()
21
1
2import json
3
4with open('path_to_file/person.json') as f:
5 data = json.load(f)
1>>> import json
2>>> data = {'item': 'Beer', 'cost':'£4.00'}
3>>> jstr = json.dumps(data, indent=4)
4>>> print(jstr)
5{
6 "item": "Beer",
7 "cost": "\u00a34.00"
8}
9
1
2import json
3
4with open('path_to_file/person.json') as f:
5 data = json.load(f)
6
7# Output: {'name': 'Bob', 'languages': ['English', 'Fench']}
8print(data)
9