New submission from Jason Hihn <ja...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue31994>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to