I’m using Google App Engine and Python.
class Spam(db.Model)
eggs = db.TextProperty
# Create some json and store it to a Spam Entity
eggs_dict = {"large":10, "medium":5, "small":24}
eggs_json = simplejson.dumps(eggs)
spam = Spam(eggs=db.Text(eggs_json))
# Later, fetch spam and then return the json as part of a Response
self.response.out.write(spam.eggs)
When I do this I get a Response that looks like:
{"large":"10","medium":"5","small":"24"}
This is my first time working with JSON + Python + GAE Datastore, and my question is that this seems to be the proper way of storing and fetching JSON Strings, but before I commit this design patter to other Entities, I wanted to see if this is a good pattern and not prone to any data errors down the road. Specifically do I need to perform any encoding on the way in or out of the Datastore?
You shouldn’t need to do any encoding when inserting a ‘string’ (you’ve serialized your dictionary to a string) into the AppEngine datastore.
I tried the following code and got back the same exact same string when retrieved from the datastore.