MacPython Logo from __future__ import *

2008-09-29

simplejson 2.0.1

Filed under: python, simplejson — bob @ 1:37 pm

simplejson (documentation) is a simple, fast, complete, correct and extensible JSON (RFC 4627) encoder/decoder for Python 2.3+. It is pure Python code with no dependencies, but features an optional C extension for speed-ups.

simplejson 2.0.1 is a minor update:

  • Fixes long encoding regression introduced in 2.0.0
  • Fixes MinGW build regression introduced in 2.0.0

I didn't manage to do a simplejson 2.0.0 release notice here but that was a MAJOR update!

  • optimized Python encoding path
  • optimized Python decoding path
  • optimized C encoding path
  • optimized C decoding path
  • switched to sphinx docs (nearly the same as the json module in python 2.6)

Even without the C speedups, it's several times faster. With the C speedups, it's WAY faster. I highly recommend that everyone update their frameworks to use the latest code.

For the primary benchmark I was concerned with (some internal data structures that Mochi uses) encoding is about 4x faster than cPickle (!), and decoding is just a tiny bit slower.

There's little excuse to use other libraries now. The fastest alternative I'm aware of is cjson 1.0.5, which is currently a little faster than simplejson 2.0.0 when decoding but is actually slower than simplejson 2.0.0 at encoding (the more important path for people vending web services). In both cases, simplejson provides more flexibility (e.g. the decoding object_hook), so a slight speed cost when decoding is probably to be expected.

There aren't really any API breaking changes, but when decoding a str input it will return str objects instead of unicode if the str is all ASCII with no escaped characters. I'm not aware of any scenario other than doctests where this could be a problem.

3 Comments »

  1. Looks like the speedups library doesn’t work with python 2.4.

    >>> from simplejson import _speedups
    Traceback (most recent call last):
    File “”, line 1, in ?
    File “build/bdist.linux-x86_64/egg/simplejson/_speedups.py”, line 7, in ?
    File “build/bdist.linux-x86_64/egg/simplejson/_speedups.py”, line 6, in __bootstrap__
    ImportError: /home/anand/.python-eggs/simplejson-2.0.1-py2.4-linux-x86_64.egg-tmp/simplejson/_speedups.so: undefined symbol: Py_IS_FINITE

    (Sorry, I couldn’t find any better place to report this error)

    Comment by Anand — 2008-10-03 @ 11:21 pm

  2. The correct place for bug reports is the google code project.

    http://code.google.com/p/simplejson

    Comment by bob — 2008-10-04 @ 1:52 pm

  3. I’ve just applied a patch that fixes this and the MSVC build and released 2.0.2.

    Comment by bob — 2008-10-04 @ 4:24 pm

RSS feed for comments on this post.

Leave a comment

Powered by WP Hashcash

Powered by WordPress