You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"
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.
Activity
jogo commentedon Jan 2, 2020
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.
serhiy-storchaka commentedon Jan 2, 2020
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().
methane commentedon Jan 4, 2020
If we support more types by default, user can not customize serialization of the type using
defaultoption.That's why we don't accept "any iterable" but only list and tuple.