[Python-ideas] Json object-level serializer

Oleg Broytman phd at phd.pp.ru
Thu Jul 29 13:40:59 CEST 2010


On Thu, Jul 29, 2010 at 01:35:41PM +0200, Tarek Ziad? wrote:
> 
> 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:

   Also there must be a deserialization hook. Pickle uses __setstate__, and
pickle stores the name of the class to call __setstate__ upon.

Oleg.
-- 
     Oleg Broytman            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.



More information about the Python-ideas mailing list