0 votes
1 view
in Python by (15.7k points)

I want to send a datetime.datetime object in serialized form from Python using JSON and deserialize in JavaScript using JSON. What is the best way to do this?

1 Answer

0 votes
by (107k points)

To send a datetime.datetime object in serialized form from Python using JSON and deserialize in JavaScript using JSON. You can add the 'default' parameter to json.dumps to handle this:

date_handler = lambda obj:(

obj.isoformat()

if isinstance(obj, (datetime.datetime, datetime.date))

else None

)

json.dumps(datetime.datetime.now(), default=date_handler) 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...