Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve json from google app engine datastore

I have stored some simple data in the GAE datastore. Now I'd like to pull it out, but I'd like to do so with the results as JSON. Is there a simple way to do this?

like image 502
Ben Avatar asked Mar 23 '26 09:03

Ben


1 Answers

You can first convert your datastore model to a dictionary and then use simplejson (python 2.5) or json (python 2.7) package to convert the dictionary to json. Typically this is how the last line of your handler will look like:

self.response.out.write(simplejson.dumps(some_datastore_entity.to_dict()))

The new ndb interface to the datastore provides a to_dict method by default. You can check it out here

like image 99
Yasser Avatar answered Mar 25 '26 00:03

Yasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!