Getting values from JSON using Python Getting values from JSON using Python python python

Getting values from JSON using Python


If you want to iterate over both keys and values of the dictionary, do this:

for key, value in data.items():    print key, value


What error is it giving you?

If you do exactly this:

data = json.loads('{"lat":444, "lon":555}')

Then:

data['lat']

SHOULD NOT give you any error at all.


Using Python to extract a value from the provided Json

Working sample:-import jsonimport sys//load the data into an elementdata={"test1" : "1", "test2" : "2", "test3" : "3"}//dumps the json object into an elementjson_str = json.dumps(data)//load the json to a stringresp = json.loads(json_str)//print the respprint (resp)//extract an element in the responseprint (resp['test1'])