JSON Pickle: Serialize your complex Python objects to JSON
Date : 2008 07 31 Category : Tech & DevelopmentJohn Paulett wanted to be able to define complex Python model objects, then seamlessly pass them into CouchDB and to client-side Javascript.
To make this happen for objects that are beyond primitive sets he created JSON Pickle which has been used on the Universal Feed Parser, and lets you do the following:
PLAIN TEXT PYTHON: >>> 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