libb.JSONDecoderISODate

class JSONDecoderISODate(**kw)[source]

Bases: JSONDecoder

JSON decoder that reads ISO date strings into datetimes.

Reads back the dates and datetimes JSONEncoderISODate writes, plus the 8-digit basic form. A string in any other shape is left as it was.

Examples

>>> JSONDecoderISODate().decode('{"dt": "2014-10-02"}')
{'dt': datetime.datetime(2014, 10, 2, 0, 0)}
>>> JSONDecoderISODate().decode('{"note": "March", "qty": "10"}')
{'note': 'March', 'qty': '10'}

Notes

  • The accepted set does not vary by interpreter: an extended date, an extended datetime, or an 8-digit basic date. A basic-format datetime (‘20141002T103000’) and an ISO week date (‘2014W011’) stay strings on every supported version.

  • An 8-digit string is a basic-format date, so a caller storing 8-digit ids as strings gets dates back.

  • A time is written by the encoder but read back as a string. It has no unambiguous ISO reading: time.fromisoformat takes '10' to 10:00 and '2024' to 20:24, so decoding times would rewrite ordinary numeric strings. A caller that knows a field holds a time converts it itself.