this post was submitted on 12 Aug 2026
921 points (97.5% liked)

Programmer Humor

32767 readers
509 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] mat@jlai.lu 1 points 22 hours ago (1 children)

Just tried it in an ipython shell

import datetime
import json

json.dumps({"a": datetime.datetime(1970,1,1)})

And I got the TypeError: datetime not JSON serializable though.

[โ€“] _stranger_@lemmy.world 1 points 21 hours ago* (last edited 21 hours ago)

If you don't care you can pass in default=str (I think) but if you do care you can define a function for what the string representation should look like and pass that in, but that's a happy path case to be honest. I usually only run into this problem when something is logging unknown data (otherwise I prefer to model data like this so the IDE is happy) so I pass in the default=str just to get it functional.

Duck typing usually works but, datetime man, datetime is the warp from Warhammer 40K, it will drive you mad.