Source

jaraco.json / example.txt

Full commit
>>> from jaraco.json.main import *
>>> from jaraco.json.test_encoding import Satchel, Marble
>>> s = Satchel()
>>> s.add(Marble('blue'))
>>> import pymongo
>>> db = pymongo.Connection().stuff
>>> db.satchels.drop()
>>> db.satchels.insert(GenericEncoder().default(s)) # doctest: +ELLIPSIS
ObjectId(...)
>>> data = db.satchels.find_one()
>>> res = decode_object_hook(data)
>>> res.items[0].color
u'blue'

You can even query the data

>>> data = db.satchels.find_one({'state.items.state.color': 'blue'})
>>> res = decode_object_hook(data)