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

Embed JSX code with if condition in React app