Writing a GenericEncoder to prevent JSON conversion errors

class GenericEncoder(json.JSONEncoder):
import numpy
def default(self, obj):
if isinstance(obj, numpy.generic):
return numpy.asscalar(obj)
elif isinstance(obj, datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
else:
return json.JSONEncoder.default(self, obj)

Comments

Popular posts from this blog

How to create an organizational chart in your webpage using Google Organization Chart Tools

How to remove “Git” from Windows 7 context menu

How to add Diggit, Technorati, Del.icio.us, Stumbleupon, Reddit and pInterest buttons to your Blogger posts