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
3data = {"key": "value"}
4
5with open('data.json', 'w') as jsonfile:
6 json.dump(data, jsonfile)
7
1import json
2
3with open('file_to_load.json', 'r') as file:
4 data = json.load(file)
1import json
2varRaw ='''
3{
4 "from":{
5 "max" : "xx:xx:xx:xx:xx:xx",
6 "ip" : "192.168.0.20"
7 },
8 "data":{
9 "id":"value",
10 "id": "value",
11 "id": "value"
12 }
13}
14'''
15#string to json
16varJson = json.loads(varRaw)
17#get values from json
18
19print(varJson['from'])
20#output wil be: {'max': 'xx:xx:xx:xx:xx:xx', 'ip': '192.168.0.20'}
21print(varJson['from']['ip'])
22#output wil be: 192.168.0.20