This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from http://taketwoprogramming.blogspot.com/2009/06/subclassing-jsonencoder-and-jsondecoder.html | |
from json import JSONEncoder, JSONDecoder | |
class DateTimeAwareJSONEncoder(JSONEncoder): | |
""" | |
Converts a python object, where datetime and timedelta objects are converted | |
into objects that can be decoded using the DateTimeAwareJSONDecoder. | |
""" | |
def default(self, obj): | |
if isinstance(obj, datetime): | |
return { |