Right now I am currently just doing this:
self.response.headers['Content-Type'] = 'application/json' self.response.out.write('{"success": "some var", "payload": "some var"}')
Is there a better way to do it using some library?
Right now I am currently just doing this:
self.response.headers['Content-Type'] = 'application/json' self.response.out.write('{"success": "some var", "payload": "some var"}')
Is there a better way to do it using some library?
webapp2
has a handy wrapper for the json module: it will use simplejson if available, or the json module from Python >= 2.6 if available, and as a last resource the django.utils.simplejson module on App Engine.http://webapp2.readthedocs.io/en/latest/api/webapp2_extras/json.html
Every place you want to return a json response...
or
python itself has a json module, which will make sure that your JSON is properly formatted, handwritten JSON is more prone to get errors.
Yes, you should use the
json
library that is supported in Python 2.7:I usually using like this: