tags:

views:

131

answers:

3

There seems to be a handful of JSON libraries out there for Python even though Python has a built-in library. One even claims to be built according to http://www.json.org spec (which caused me to think 'hmmm, is Python's built in library not built fully to spec?', so I find myself here to ask what others have found when trying out different libraries. Is there any difference?

I will be using it for a Django-based web AJAX API (I know there are Django apps for this, but I want to get at the root of this before I just grab an app).

+4  A: 

The built in library is fine most of the time although occasionally you can get issues to do with character encoding.

There is cjson if you have performance issues to deal with.

Personally, I just use simplejson - for no particular reason.

Rich
When you say "simplejson" are you talking about the Django util?
orokusaki
This: http://pypi.python.org/pypi/simplejson/It might well come in Django; I'm not sure. Just try importing it to see.
Rich
@Rich: It's called `json` in Python >2.6 and is already installed.
S.Lott
@orokusaki : `django.utils.simplejson` is actually loading the "best" json implementation it can find. It can be either `simplejson`, `json` built-in (if available), or django's own JSON implementation. The precise priority rules for loading one implementation over one another can be found in the source code, in `utils/simplejson/__init__.py`.
Clément
@Clement : Ahh that's awesome. I didn't know that.
Rich
+3  A: 

Python < 2.6 did not include json module. The presence of multiple JSON implementations says nothing about the quality of the built-in module and everything about the history of having no built-in json.

I suggest that your assumption (multiple implemntations means low quality in the library) is false.

S.Lott
1+ Thx S. Lott, so that's why there's others. I was always curious and now that I need JSON in my app the question arose.
orokusaki
From the simplejson homepage: "simplejson is the externally maintained development version of the json library included with Python 2.6 and Python 3.0, but maintains backwards compatibility with Python 2.4 and Python 2.5". It's not just the same interface, it's (mostly) the same code.
mzz
+1  A: 

The built-in module json works perfect. If you have to use an earlier python, use simplejson, a third-party module (which is exactly the same interface). These have the serialization interface you expect from Python and are widely used.

(simple)json by default has some very minor extensions of the JSON standard. You can read about these in the documentation for json and disable them if you want to for some reason.

Mike Graham
Thanks Mike. I assume that Django's simplejson is just the simplejson library then, without any added Django-specific stuff.
orokusaki