Python json encode datetime
Fix TypeError: datetime.datetime is not JSON serializable error.
import datetime
import json
from django.core.serializers.json import DjangoJSONEncoder
print json.dumps({
'timestamp': datetime.datetime.now(),
}, cls=DjangoJSONEncoder, indent=2)
Comments
Leave a Reply