Skip to content

Instantly share code, notes, and snippets.

@andycasey
Created February 13, 2013 08:11
Show Gist options
  • Save andycasey/4943031 to your computer and use it in GitHub Desktop.
Save andycasey/4943031 to your computer and use it in GitHub Desktop.
mrmagoo:smh andycasey$ python -c 'import json;import numpy as np;a=np.arange(5);b=a.tolist();c=list(a);print b,c,b==c;print json.dumps(b);print json.dumps(c)'
[0, 1, 2, 3, 4] [0, 1, 2, 3, 4] True
[0, 1, 2, 3, 4]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/json/encoder.py", line 201, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/json/encoder.py", line 264, in iterencode
return _iterencode(o, 0)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/json/encoder.py", line 178, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 0 is not JSON serializable
@andycasey
Copy link
Author

Well, it looks like this behaviour has been fixed in a recent version of json/numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment