Is Go faster than Python on Google App Engine?

Google App Engine: How can I turn results from an API into a Python dictionary?

  • I'm making an app using Google app engine. I want to query an API, get JSON results, and use the dictionary in my app. Many tutorials I've seen for this use Python libraries that I don't seem to have natively in Google App Engine. Is there an easy way to do it with Python default libraries? Alternatively, how can I install necessary libraries in GAE?

  • Answer:

    Google AppEngine has now been upgraded to Python 2.7, so you can use the built-in json module. import json data = '{"site": "quora", "url": "http://quora.com/", "metadata": {"visitors": 10000}}' response = json.loads(data) You can then access the fields in this dictionary as you would any other dictionary. E.g., response['site'] will output "quora", and response['metadata']['visitors'] will output 10000. Python pre-2.6 does not have the json module, so if you're using an older Python, you'll have to use simplejson, which exists in both Django and its own package (pip install simplejson or pip install django). Django 1.2 is pre-installed on the AppEngine Python environment. Simplejson has an identical API to the built-in json module. try: import json except ImportError: try: import simplejson as json except ImportError: from django.utils import simplejson as json data = '{"site": "quora", "url": "http://quora.com/"}' response = json.loads(data)

Dan Loewenherz at Quora Visit the source

Was this solution helpful to you?

Other answers

For Python3.x one will need a simple modification to the answer by Dan Loewenherz(to account for text and data  instead of Unicode and 8-bit): def _jsonConvertByteToString(response): data = response.decode('utf-8') return json.loads(data) For more details see: http://docs.python.org/3.0/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit

Shubhra Sharma (शुभ्रा शर्मा)

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.