[New-bugs-announce] [issue18303] json.dumps() claims numpy.bool_ is not serializable

miscjunk report at bugs.python.org
Tue Jun 25 23:43:54 CEST 2013

New submission from miscjunk:

When json.dumps() is called on a numpy.bool_ object, it crashes.

To recreate:
import numpy as np
import json
a = np.array([1,2,3,4,5,6])
a = a < 5
json.dumps(a) #crash
json.dumps(a[0]) #crash
json.dumps(a.tolist()) #this works!

Example of error output
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "..\python-3.3.2.amd64\lib\json\__init__.py", line 236, in dumps
    return _default_encoder.encode(obj)
  File "..\python-3.3.2.amd64\lib\json\encoder.py", line 191, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "..\python-3.3.2.amd64\lib\json\encoder.py", line 249, in iterencode
    return _iterencode(o, 0)
  File "..\python-3.3.2.amd64\lib\json\encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: False is not JSON serializable

components: Extension Modules, Library (Lib)
messages: 191887
nosy: miscjunk
priority: normal
severity: normal
status: open
title: json.dumps() claims numpy.bool_ is not serializable
type: crash
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list