This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients ethan.furman, miscjunk, r.david.murray
Date 2013-06-26.06:09:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1372226998.35.0.570802795479.issue18303@psf.upfronthosting.co.za>
In-reply-to
Content
For the curious, here are all the tracebacks:

--> json.dumps(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.3/json/encoder.py", line 191, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.3/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: array([ True,  True,  True,  True, False, False], dtype=bool) is not JSON serializable


--> json.dumps(a[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.3/json/encoder.py", line 191, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.3/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: True is not JSON serializable

While the repr says 'True', the type is <class 'numpy.bool_'>.


and the success:

--> json.dumps(a.tolist()) #this works!
'[true, true, true, true, false, false]'


Summary
=======

No bug here, defined behavior.  Raising the issue with NumPy won't help as this is not a bug... although perhaps they have a json handler already written somewhere?  At any rate, yes, said handler would have to be specified as the 'default' parameter.
History
Date User Action Args
2013-06-26 06:09:58ethan.furmansetrecipients: + ethan.furman, r.david.murray, miscjunk
2013-06-26 06:09:58ethan.furmansetmessageid: <1372226998.35.0.570802795479.issue18303@psf.upfronthosting.co.za>
2013-06-26 06:09:58ethan.furmanlinkissue18303 messages
2013-06-26 06:09:58ethan.furmancreate