Skip to content

Instantly share code, notes, and snippets.

import simplejson as json
import lxml
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> json.dumps(obj, cls=objectJSONEncoder)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""