I have a basic dict as follows:
sample = {} sample[\'title\'] = \"String\" sample[\'somedate\'] = somedatetimehere
Here is my solution:
import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super().default(obj) except TypeError: return str(obj)
Then you can use it like that:
json.dumps(dictionnary, cls=DatetimeEncoder)