a = OrderedDict([('a', datetime.datetime(2015, 6, 15, 15, 58, 54, 884000)),
    ('b', 'b'), ('c', 'c'), ('d', 'd')])
print(a)

def encoder(obj):
    if type(obj) is datetime.datetime:
        return {'$date$': obj.timestamp()}
raise TypeError
s = json.dumps(a, default=encoder)
print(('JSON:', s))

def decoder(obj):
    if len(obj) == 1 and len(obj[0]) == 2 and obj[0][0] == '$date$':
        return datetime.datetime.fromtimestamp(obj[0][1])
python - using json with OrderedDict and Datetime