Thursday, July 31st, 2008
JSON Pickle: Serialize your complex Python objects to JSON
John 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:
-
-
>>> 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
-












nice work!
definitely see a use for this