➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: json fails to encode dictionary view types
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: jogo, methane, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-01-02 19:10 by jogo, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg359212 - (view) Author: Joe Gordon (jogo) Date: 2020-01-02 19:10
Python 3 fails to encode dictionary view objects. Assuming this is an expected behavior, what is the thinking behind it? I was unable to find any documentation around this.

> import json; json.dumps({}.values())
"TypeError: Object of type dict_values is not JSON serializable"
msg359216 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-01-02 19:58
To handle non-standard types you can implement the default() method in the subclass of json.JSONEncoder (https://docs.python.org/3/library/json.html#json.JSONEncoder.default) or pass the corresponding argument to json.JSONEncoder() or json.dumps().
msg359272 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-01-04 02:32
If we support more types by default, user can not customize serialization of the type using `default` option.
That's why we don't accept "any iterable" but only list and tuple.
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83377
2020-01-04 02:32:27methanesetstatus: open -> closed
resolution: wont fix
stage: resolved
2020-01-04 02:32:16methanesetnosy: + methane
messages: + msg359272
2020-01-02 19:58:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg359216
2020-01-02 19:10:57jogocreate