Python 2.6 json & encoding of datetime.

David Wilson dw at botanicus.net
Fri Oct 10 20:39:33 EDT 2008


Hi there,

I've been playing with Python's new json library, and found myself
facing a seemingly simple problem: encoding of datetime objects. Some
'jsonlib' that I was using previously was unable to do this, and the
new built-in json module shares the same limitation.

A bit of googling around brought me to <http://www.west-wind.com/
WebLog/posts/214731.aspx> which seems to suggest there is no
standardised way of doing it. Indeed, reading the rather sparse JSON
RFC makes no mention of it.

It appears my only possibility is writing little helper functions to
convert my datetimes to/from ISO8601 strings or UNIX timestamps, but
this just feels wrong. Suggestions?

Thanks,


David.



More information about the Python-list mailing list