Parse JSON in Python

advertisements

My project is currently receiving a JSON message in python which I need to get bits of information out of. For the purposes of this, lets set it to some simple JSON in a string:

jsonStr = '{"one" : "1", "two" : "2", "three" : "3"}'

So far I've been generating JSON requests using a list and then json.dumps but to do the opposite of this I think I need to use json.loads but I haven't had much luck with it. Could anyone provide me a snippet that would return "2" with the input of "two" in the above example?


Very simple:

import json
j = json.loads('{"one" : "1", "two" : "2", "three" : "3"}')
print j['two']