jsonpickle 0.0.5

John Paulett john at 7oars.com
Thu Jul 31 03:06:54 CEST 2008


I would like to announce jsonpickle 0.0.5.

jsonpickle allows for any Python object to be serialized into JSON. This 
library acts as an extension to simplejson. Whereas simplejson only 
serializes primitive objects (str, int, float, list, dict, etc), 
jsonpickle can handle most non-builtin Python objects. jsonpickle 
recursively examines Python objects and collections (dictionaries, 
lists, tuples, and sets), and converts non primitive objects to a 
primitive version.

This module is the result of a desire to store model objects into 
CouchDB, with no upfront specification of field mapping.

jsonpickle has been tested primarily with the Universal Feed Parser and 
CouchDB.  Feedback on other systems that do not properly serialize is 
greatly appreciated!


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

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

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

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

# The new object has the same type and data, but essentially is now a
#copy of the original.
 >>> obj == unpickled
 >>> obj.name == unpickled.name
 >>> type(obj) == type(unpickled)

# If you will never need to load (regenerate the Python class from
# JSON), you can pass in the keyword unpicklable=False to prevent extra
# information from being added to JSON.
 >>> oneway = jsonpickle.dumps(obj, unpicklable=False)
 >>> print oneway
{"name": "A String", "child": null}


License: New BSD
Discussion Group: http://groups.google.com/group/jsonpickle


John Paulett
john at 7oars.com
Blog: http://blog.7oars.com/

More information about the Python-announce-list mailing list