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, let's 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
. However 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?
'
single-quote string delimiters, you may have accidentally created string representations for Python dictionaries instead. JSON will always use"
delimiters. If so, repair your code that produces that output to usejson.dumps()
instead ofstr()
orrepr()
, and head over to Convert a String representation of a Dictionary to a dictionary? to figure out how to recover your Python data. Other clues you have a Python literal? Look forNone
,True
orFalse
, JSON would usenull
,true
&false
. - Martijn Pieters♦'
single-quote string delimiters), also have a look here: stackoverflow.com/questions/41168558/… - questionto42