classification
Title: json encoder exception could be better
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: JSON encode: more informative error
View: 26623
Assigned To: Nosy List: Jason Hihn, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-11-09 19:05 by Jason Hihn, last changed 2017-11-10 19:33 by serhiy.storchaka. This issue is now closed.

Messages (3)
msg305980 - (view) Author: Jason Hihn (Jason Hihn) Date: 2017-11-09 19:05
Given this traceback:
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 7.0374198 is not JSON serializable

It would actually be better to have the error reported as type(o)+ " is not JSON serializable."  because at first glance, 7.0374198 *is* serializable. In this specific case, the issue can be fixed by attempting to serialize float(o), because it is a ndarray. Maybe there's a better way to do numpy types or some kind of automatic conversion but for now, this is only a request to alter the message, I'd hope to something like:

repr(o) + " of type " + type(o) + " is not JSON serializable"

It's it's really more about the type rather than the value being serialized.
msg306043 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-10 19:28
This is a duplicate of issue24641.
msg306044 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-10 19:33
Actually it was fixed in issue26623.
History
Date User Action Args
2017-11-10 19:33:35serhiy.storchakasetsuperseder: Log type of unserializable value when raising JSON TypeError -> JSON encode: more informative error
messages: + msg306044
2017-11-10 19:28:24serhiy.storchakasetstatus: open -> closed

superseder: Log type of unserializable value when raising JSON TypeError

nosy: + serhiy.storchaka
messages: + msg306043
resolution: duplicate
stage: resolved
2017-11-09 19:05:23Jason Hihncreate