[Python-ideas] Json object-level serializer
solipsis at pitrou.net
Thu Jul 29 14:57:13 CEST 2010
On Thu, 29 Jul 2010 14:47:34 +0200
Daniel Fetchinson <fetchinson at googlemail.com>
> > What about adding in the json package the ability for an object to
> > provide a different object to serialize ?
> > This would be useful to translate a class into a structure that can be
> > passed to json.dumps
> > So, it __json__ is provided, its used for serialization instead of the
> > object itself:
> >>>> import json
> >>>> class MyComplexClass(object):
> > ... def __json__(self):
> > ... return 'json'
> > ...
> >>>> o = MyComplexClass()
> >>>> json.dumps(o)
> > '"json"'
> Have a look at turbojson , the jsonification package that uses
> peak.rules  and which comes with turbogears . It does exactly
> what you propose.
That it uses PEAK-Rules is probably a good reason to avoid it.
Also, AFAIK, TurboGears have stopped using turbojson and relies on
More information about the Python-ideas