Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 2
    You should use isinstance(o, (datetime.date, datetime.datetime,)). Probably wouldn't hurt to include datetime.time too. Commented May 10, 2014 at 6:56
  • I don't think this is a good solution anymore. Probably the conversions should take a more privileged place -- and also a more understandable place -- in your code, so you know what you are converting to when you put things into a database, or whatever, instead of having everything being done by a transparent function. But I don't know. Commented May 10, 2014 at 11:31
  • 3
    JSON is good for serialising data for processing later. You may not know exactly what that data is. And you shouldn't need to. Serialising JSON should just work. Just like converting unicode to ascii should. Python's inability to do this without obscure functions makes it annoying to use. Database validation is a separate issue IMO. Commented May 11, 2014 at 11:52
  • No, it shouldn't "just work". If you don't know how the serialization occurred and has to access the data later from another program/language, then you're lost. Commented May 12, 2014 at 1:45
  • 3
    JSON is commonly used for strings, ints, floats, dates (I'm sure others use currency, temperatures, commonly too). But datetime is part of the standard library and should support de/serialisation. If it wasn't for this question, I'd still be manually searching my incredibly complex json blobs (which I didn't always create the structure for) for dates and serialising them 1 by 1. Commented May 13, 2014 at 3:11