[Python-ideas] Json object-level serializer (original) (raw)
Daniel Fetchinson fetchinson at googlemail.com
Thu Jul 29 15:19:56 CEST 2010
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 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 [1], the jsonification package that uses peak.rules [2] and which comes with turbogears [3]. It does exactly what you propose. That it uses PEAK-Rules is probably a good reason to avoid it.
Why?
Also, AFAIK, TurboGears have stopped using turbojson and relies on [simple]json instead.
That might be true for turbogears2 but turbogears1 (which is still in active development) still uses turbojson. Turbogears 1 and 2 diverged so much that it would be more appropriate to call them different names and consider them different projects (I personally use and prefer tg1).
Cheers, Daniel
-- Psss, psss, put it down! - http://www.cafepress.com/putitdown
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]