I am getting a json object from a remote server, and converting it to a python string like this:
a = eval(response)
Is this stupid in any way, or do I have a better option?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using
evalis not a good way to process JSON:JSON isn’t even valid Python, because of
true,false, andnull.evalwill execute arbitrary Python code, so you are at the mercy of malicious injection of code.Use the
jsonmodule available in the standard library instead:If you’re using a version of Python older than 2.6, you’ll need to download the module yourself. It’s called
simplejsonand can be downloaded from PyPi.