[Python-ideas] Json object-level serializer (original) (raw)
Mike Graham mikegraham at gmail.com
Thu Jul 29 15:01:27 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 ]
On Thu, Jul 29, 2010 at 7:35 AM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
Hello,
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"' Cheers Tarek -- Tarek Ziadé | http://ziade.org
Since there isn't really any magic going on, why use a foo name? The majority of foo names are for things you shouldn't reference yourself, but it doesn't seem like this is too personal a method to do that with.
This allows inheritance of JSONization. The current custom serialization stuff does not. I'm not certain which is the bug and which is the feature.
Since you aren't using anything useful from the json module, why involve it at all? Consistent API?
One nice thing about the json module is that when using it you always produce valid JSON. Even the hooks for custom serialization keep this property. This is fairly nice to have.
Regards, Mike
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]