[issue35111] Make Custom Object Classes JSON Serializable

2018-10-31 Thread Bob Ippolito
Bob Ippolito added the comment: That's what the for_json method is in simplejson, it does not have widespread usage. You can implement that when encoding: ``` def json_default(obj): try: return obj.__json__() except AttributeError: raise TypeError("{} can not be JSON

[issue35111] Make Custom Object Classes JSON Serializable

2018-10-31 Thread andrew c
andrew c added the comment: Bob, I understand what you are saying, but having a built-in is way easier than encoder/decoders. You can still have both actually. Even if you didn't have two way, a one way would be amazingly helpful. For large development systems, a __json__ method would ma

[issue35111] Make Custom Object Classes JSON Serializable

2018-10-30 Thread Bob Ippolito
Bob Ippolito added the comment: The trouble with having such a hook is that it would take precedence over any customization you might want or need to do to satisfy the protocol you're implementing. Other than the limited set of types that are part of the JSON specification, there's essential

[issue35111] Make Custom Object Classes JSON Serializable

2018-10-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: > If you can serialize an object using pickle, > why not have the ability to serialize objects using json? One reason would be that the JSON spec was intentionally designed to handle a limited number of types so that it would have maximum interoperability

[issue35111] Make Custom Object Classes JSON Serializable

2018-10-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> bob.ippolito nosy: +bob.ippolito ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35111] Make Custom Object Classes JSON Serializable

2018-10-30 Thread andrew c
New submission from andrew c : When creating a custom class that doesn't inherit from the accepted classes, there is no way to serialize it using json.dumps or json.dump. I propose that __fromjson__ and __tojson__ that when present will be used by the Python's default encoder. This issue i