1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5
6print(data)
1import json
2
3uglyjson = '{"firstnam":"James","surname":"Bond","mobile":["007-700-007","001-007-007-0007"]}'
4
5#json.load method converts JSON string to Python Object
6parsed = json.loads(uglyjson)
7
8print(json.dumps(parsed, indent=2, sort_keys=True))
1import json
2
3data = {"key": "value"}
4
5with open('data.json', 'w') as jsonfile:
6 json.dump(data, jsonfile)
7
1import json
2
3appDict = {
4 'name': 'messenger',
5 'playstore': True,
6 'company': 'Facebook',
7 'price': 100
8}
9app_json = json.dumps(appDict)
10print(app_json)