[New-bugs-announce] [issue31994] json encoder exception could be better

Jason Hihn report at bugs.python.org
Thu Nov 9 14:05:23 EST 2017


New submission from Jason Hihn <jason at apkudo.com>:

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.

----------
components: Extension Modules
messages: 305980
nosy: Jason Hihn
priority: normal
severity: normal
status: open
title: json encoder exception could be better
type: enhancement
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31994>
_______________________________________


More information about the New-bugs-announce mailing list