All, I would like to announce jsonpickle 0.0.5. http://code.google.com/p/jsonpickle/ 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 False obj.name == unpickled.name True type(obj) == type(unpickled) True
# 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 Thanks, John Paulett john@7oars.com Blog: http://blog.7oars.com/
participants (1)
-
John Paulett