Author thomas-arildsen
Recipients thomas-arildsen
Date 2015-05-28.08:32:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432801951.51.0.0124262456045.issue24313@psf.upfronthosting.co.za>
In-reply-to
Content
When I run the attached example in Python 2.7.9, it succeeds. In Python 3.4, it fails as shown below. I use json 2.0.9 and numpy 1.9.2 with both versions of Python. Python and all packages provided by Anaconda 2.2.0.
The error seems to be caused by the serialised object containing a numpy.int64 type. It might fail with other 64-bit numpy types as well (untested).

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/tha/tmp/debug_json/debug_json.py in <module>()
      4 test = {'value': np.int64(1)}
      5 
----> 6 obj=json.dumps(test)

/home/tha/.conda/envs/python3/lib/python3.4/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    228         cls is None and indent is None and separators is None and
    229         default is None and not sort_keys and not kw):
--> 230         return _default_encoder.encode(obj)
    231     if cls is None:
    232         cls = JSONEncoder

/home/tha/.conda/envs/python3/lib/python3.4/json/encoder.py in encode(self, o)
    190         # exceptions aren't as detailed.  The list call should be roughly
    191         # equivalent to the PySequence_Fast that ''.join() would do.
--> 192         chunks = self.iterencode(o, _one_shot=True)
    193         if not isinstance(chunks, (list, tuple)):
    194             chunks = list(chunks)

/home/tha/.conda/envs/python3/lib/python3.4/json/encoder.py in iterencode(self, o, _one_shot)
    248                 self.key_separator, self.item_separator, self.sort_keys,
    249                 self.skipkeys, _one_shot)
--> 250         return _iterencode(o, 0)
    251 
    252 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

/home/tha/.conda/envs/python3/lib/python3.4/json/encoder.py in default(self, o)
    171 
    172         """
--> 173         raise TypeError(repr(o) + " is not JSON serializable")
    174 
    175     def encode(self, o):

TypeError: 1 is not JSON serializable
History
Date User Action Args
2015-05-28 08:32:31thomas-arildsensetrecipients: + thomas-arildsen
2015-05-28 08:32:31thomas-arildsensetmessageid: <1432801951.51.0.0124262456045.issue24313@psf.upfronthosting.co.za>
2015-05-28 08:32:31thomas-arildsenlinkissue24313 messages
2015-05-28 08:32:31thomas-arildsencreate