python read values from json file code example
Example 1: python read json file
import json
with open('path_to_file/person.json') as f:
data = json.load(f)
print(data)
Example 2: read json file python
import json
with open('path_to_file/person.json') as f:
data = json.load(f)
print(data)
flx = json.dumps(data, ensure_ascii=False, indent=4)
print(flx)
Example 3: python read json file
import json
varRaw ='''
{
"from":{
"max" : "xx:xx:xx:xx:xx:xx",
"ip" : "192.168.0.20"
},
"data":{
"id":"value",
"id": "value",
"id": "value"
}
}
'''
#string to json
varJson = json.loads(varRaw)
#get values from json
print(varJson['from'])
#output wil be: {'max': 'xx:xx:xx:xx:xx:xx', 'ip': '192.168.0.20'}
print(varJson['from']['ip'])
#output wil be: 192.168.0.20