views:

204

answers:

3

What is the best JSON library to get JSON data for Django, 'simplejson' or otherwise?

thanks very much

A: 

I've had pretty good experience with simplejson.

nstehr
+7  A: 

Python 2.6 comes with a json module in the standard library -- so that would be best if you're on Python 2.6; for older Python versions, simplejson may be roughly equivalent.

Alex Martelli
+6  A: 

Django itself integrates simplejson and has the ability to use your own version from the system if you have it installed.

from django.core import serializers
json_serializer = serializers.get_serializer("json")()

As Alex notes, the json module is bundled with Python 2.6 and above -- that's actually simplejson source pulled into Python core. This might demonstrate to you that it has wide acceptance in the Python community.

The reason that you may want to use your own version is that simplejson when compiled with C extensions and cjson, a different module, are substantially more performant than the versions bundled with Django or Python.

Michael Greene
Actually, `django.contrib.simplejson` will use the standard library `json` module if it's available. That is, on Python 2.6+, `from django.utils import simplejson` will actually give you back the standard library's `json` module. The stdlib module, in turn, transparently loads the C extension if it's availableSo, if you're using Django, there's no good reason not to always use `django.utils simplejson`.
jacobian