import datetime, json
D = {datetime.datetime.now(): 'foo', datetime.datetime.now(): 'bar'}
new_D = {}
for k, v in D.items():
    pass
How to dump a Python dictionary to JSON when keys are non-trivial objects?