views:

3124

answers:

5

I'd like to parse a JSON string into an object under Google App Engine (python). What do you recommend? Something to encode/stringify would be nice too. Is what you recommend built in, or a library that I have to include in my app? Is it secure? Thanks.

+2  A: 

Include the simplejson library with you app?

uswaretech
A: 

Look at the python section of json.org. The standard library support for JSON started at python 2.6, which I believe is newer than what the app engine provides. Maybe one of the other options listed?

Yuval F
A: 

If you're using Python2.6 or greater, I've used with success the built-in json.load function. Otherwise, simplejson works on 2.4 without dependencies.

cpharmston
AppEngine uses Python 2.5. You should not be developing using 2.6+.
Sridhar Ratnakumar
+25  A: 

Consider using Django's json lib, which is included with GAE.

from django.utils import simplejson as json

# load the object from a string
obj = json.loads( string )

The link above has examples of Django's serializer, and here's the link for simplejson's documentation.

If you're looking at storing Python class instances or objects (as opposed to compositions of lists, strings, numbers, and dictionaries), you probably want to look at pickle.

I hope that helps.

Incidentally, to get Django 1.0 (instead of Django 0.96) running on GAE, you can use the following call in your main.py, per this article:

from google.appengine.dist import use_library
use_library('django', '1.0')
Brian M. Hunt
A: 

Google is currently using Python 2.5 on Google App Engine. When/if google upgrades GAE to python 2.6, you can do the following:

import json
out_json = json.dumps(in_dictionary_vals)
speedplane