[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2020-10-19 Thread Éric Araujo
Éric Araujo added the comment: See also #30343 -- nosy: +eric.araujo ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2020-06-06 Thread Bob Ippolito
Bob Ippolito added the comment: I would certainly reconsider it at this point, I think a bona fide ABC *specific to JSON encoding* would be a good way to do it. simplejson has two ways to do this, the `for_json` parameter which will use a `for_json()` method on any object as the JSON

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2020-06-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: +1 for reconsidering whether the json module should support mappings that don't inherit for dict. The decision not to support general mappings is ancient and predates a lot of modern tooling. The only worry is that the objects won't round-trip — you

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2020-06-06 Thread Nathaniel Manista
Nathaniel Manista added the comment: Err, "... it's something that complicates writing code according to...", sorry. -- ___ Python tracker ___

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2020-06-06 Thread Nathaniel Manista
Nathaniel Manista added the comment: There's a great deal more additional discussion about this over at https://discuss.python.org/t/json-does-not-support-mapping-and-mutablemapping/2829, but I would like to heartily "hear hear" this issue for the way it is weird that

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2019-05-27 Thread zgoda.mobica
zgoda.mobica added the comment: In particular case of lazy type proxy objects the result of dump() may be different than dumps() because dump does iterencode() over data and possibly causing proxy object evaluation. In such case dumps() will raise TypeError but dump() will not. --

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-10-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Using the default method or argument is a proper way of serializing custom types to JSON. There are a number of issues fr adding support for serializing different types by default. I work on a patch that will allow to make different types serializable in

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-10-01 Thread Michael Smith
Michael Smith added the comment: OK, I appreciate the response. The MappingProxy objects I am working with are in a nested data structure, so accessing them to coerce them directly isn't feasible. I created class MappingProxyEncoder(JSONEncoder): def default(self, obj): if

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-09-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: IIRC, there was an early decision to handle only exact types and their subclasses (plus tuples). For example, os.environ and instances of collections.ChainMap are not JSON serializable. I believe the reason was that it made encoding faster, more

[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-09-30 Thread Michael Smith
New submission from Michael Smith : If a mappingproxy object is a read-only proxy to a mapping, would it make sense for them to JSON serialize just like the mapping they come from? Currently, json.dumps throws the "I don't know how to serialize this" error: $ python -c 'import json > import