This question already has an answer here:
I have a string with utf-8 encoding, like
>>> print s
"{u'name':u'Pradip Das'}"
Basically I load some data from JSON file and it loads as above. Now, I want to covert this string in to python dictionary. So I can do like:
>>> print d['name']
'Pradip Das'
Use EVAL to convert string to dictionary.
Let me know if there are any batter way to do so.
You can use the built-in
ast.literal_eval
:This is safer than using
eval
. As the docs itself recommends it:Additionally, you can read this article which will explain why you should avoid using
eval
.