Thursday, August 21, 2008

jsonpickle 0.1.0 released

Thanks to Adam for finding the bug that missed longs as a primitive type.

In addition to that quick bugfix, jsonpickle has undergone a major API change. At the core of this change is jsonpickle's new preference for python-cjson over simplejson. While python-cjson is not a requirement, if it is installed on the machine, jsonpickle will use python-cjson. python-cjson is faster for jsonpickle (see the benchmarks), but simplejson is still useful on Google's App Engine.

So the API change moves away from the load/loads/dump/dumps functions in the tradition of simplejson towards a simple encode/decode set of functions. If you need to save the output or read a file, you can do that on your own, then send that data into the encode/decode methods. While it may have been smart to deprecate these functions first, I want to get the API correct early on and prevent cruft.

The update example:

>>> import jsonpickle
>>> from jsonpickle.tests.classes import Thing

Create an object.
>>> obj = Thing('A String')
>>> print
A String

Use jsonpickle to transform the object into a JSON string.
>>> pickled = jsonpickle.encode(obj)
>>> print pickled
{"classname__": "Thing", "child": null, "name": "A String", "classmodule__": "jsonpickle.tests.classes"}

Use jsonpickle to recreate a Python object from a JSON string
>>> unpickled = jsonpickle.decode(pickled)
>>> print
A String

Grab the new version.

Thanks also go out to the Joose developers for integrating jsonpickle into their product!

No comments: