Answers for "object of type 'datetime' is not json serializable"

2

json dumps datetime

def myconverter(o):
    if isinstance(o, datetime.datetime):
        return o.__str__()

print(json.dumps(d, default = myconverter))
Posted by: Guest on June-23-2020
1

object of type 'datetime' is not json serializable

from datetime import datetime
import json

class DateTimeEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, datetime):
            return o.isoformat()

        return json.JSONEncoder.default(self, o)
Posted by: Guest on May-07-2021

Code answers related to "object of type 'datetime' is not json serializable"

Code answers related to "Javascript"

Browse Popular Code Answers by Language