views:

1560

answers:

5

I have seen many a projects use simplejson module than the in builtin Standard Library json.

Also there seem to be many different simplejson modules

What are the advantages of simplejson and which implementation is good?

Why not, just use the standard builtin json module?

+3  A: 

The builtin json module got included in Python 2.6. Any projects that support versions of Python < 2.6 need to have a fallback. In many cases, that fallback is simplejson.

thedz
+18  A: 

json is simplejson, added to the stdlib. Since json was only added in 2.6, simplejson has the advantage of working on more python versions (2.4+, rather than 2.6+). Also, simplejson is updated more frequently than Python is, so if you need the latest version for some reason, it's best to use simplejson itself.

A good practice, in my opinion, is to use it as a fallback.

try: import json
except ImportError: import simplejson as json
Devin Jeanpierre
+1  A: 

Here's (a now outdated) comparison of Python json libraries:

Comparing JSON modules for Python

Regardless of the results in this comparison you should use the standard library json if you are on Python 2.6. And.. might as well just use simplejson otherwise.

Van Gale
+1  A: 

Another reason projects use simplejson is that the builtin json did not include its C speedups, so the performance difference is noticeable.

Coady
A: 

simplejson module is simply 1,5 times faster than json (On my computer, with simplejson 2.1.1 and Python 2.7 x86).

If you want, you can try the benchmark: http://abral.altervista.org/jsonpickle-bench.zip On my PC simplejson is faster than cPickle. I would like to know also your benchmarks!

Probably, as said Coady, the difference between simplejson and json is that simplejson includes _speedups.c. So, why don't python developers use simplejson?

Jeko