jhcore.com

07 Jun, 2008

jsonpickle

Posted by: john In: Ubuntu

I have been working on an open source project, jsonpickle. The goal of the project is to be able to serialize a Python object into standard JSON notation. Python can “pickle” objects into a special binary format, but sometimes it is nice to get a human-readable format. Especially with projects like CouchDB that have use a JSON-based API.

jsonpickle is on its seconds release and can now officially handle Mark Pilgrim’s Universal Feed Parser. Feel free to join in by finding bugs and working on the code!

It is pretty easy to use:

>>> import feedparser, jsonpickle
>>> doc = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml")
>>> pickled = jsonpickle.dumps(doc)
>>> unpickled = jsonpickle.loads(pickled)
>>> doc['feed']['title'] == unpickled['feed']['title']
True

3 Responses to "jsonpickle"

1 | Dave R

June 8th, 2008 at 12:54 pm

is it more complicated than this?

simplejson.dump(obj, self.response.out)

2 | john

June 8th, 2008 at 7:58 pm

Dave, simplejson.dumps(obj) would definitely work for objects that have a directly corresponding type in JSON (e.g. str, int, float, dict, list). However, for complex objects, such as the FeedParserDict (a dict subclass), simplejson has no way of knowing how to convert it to JSON. simplejson does have a mechanism for defining how to convert complex objects, but it requires an upfront definition by every programmer who uses this feature. jsonpickle aims to handle this automatically for any non-builtin Python type.

3 | plok

July 4th, 2008 at 1:11 pm

News at Couch…

Welcome to yet another installment of News at Couch, our review of what’s new with, on and around CouchDB.

CouchDB 0.8.0 was released! Biiig news. This is our first release with the ASF and we are all very pleased with this. Great work everybod…

Comment Form

Categories

About

A source for news, reviews, guides, and tools for technology by John Paulett. Featured on Planet Ubuntu Users.

Also check out: