Read and write json files with datetime objects
Project description
Datetime JSON
Serialize and deserialize datetime objects to and from JSON.
This package provides:
-
4 functions that wrap the
json
module:load/loads
- Deserialize a JSON string containing datetime objectsdump/dumps
- Serialize python object containting datetime objects to JSON
-
two classes that wrap derived from
json.JSONEncoder
andjson.JSONDecoder
:JSONEncoder
- Serialize a datetime object to JSONJSONDecoder
- Deserialize a JSON string to a datetime object
Usage:
>>> from datetimejson import dumps, loads
>>> from datetime import datetime
>>> now = datetime.now()
>>> print(now)
2023-02-13 11:27:56.687439
>>> json_string = dumps(now)
>>> print(json_string)
{"__type__": "datetime", "year": 2023, "month": 2, "day": 13, "hour": 11, "minute": 27, "second": 56, "microsecond": 687439}
>>> print(loads(json_string))
2023-02-13 11:27:56.687439
>>>
Original code by @ApptuitAI: https://gist.github.com/abhinav-upadhyay/5300137
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
datetimejson-0.1.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for datetimejson-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a00d884f4fdfce29a2b62443915a1f190ea85e70a361d42769534c8354c8419 |
|
MD5 | 4abedc2d946cc5460ff3bcba263ce408 |
|
BLAKE2b-256 | a1caab79412f407e1f0c17d11aaae1aee90fc42e4f904aada4ae2d1bb4153dee |