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 corresponding functions of the
jsonmodule:load/loads- Deserialize a JSON string containing datetime objectsdump/dumps- Serialize python object containting datetime objects to JSON
-
two classes derived respectively from
json.JSONEncoderandjson.JSONDecoder:DateTimeEncoder- Serialize a datetime object to JSONDateTimeDecoder- Deserialize a JSON string to a datetime object
Installation
pip install datetimejson
Usage
Just replace json import by datetimejson in your code:
>>> 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datetimejson-0.1.8.tar.gz.
File metadata
- Download URL: datetimejson-0.1.8.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeb6439e41459ad0692d246ecece747324a6b0afd63fa2e50c3fdebad64a2f1d
|
|
| MD5 |
e156b6372f371a98be14066ca41aa7af
|
|
| BLAKE2b-256 |
0f807f8821d0bd3b340c5aa2ae276928bbbf5796c4baf12b48f0cd150173d06c
|
File details
Details for the file datetimejson-0.1.8-py3-none-any.whl.
File metadata
- Download URL: datetimejson-0.1.8-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01f36d3893e603357cd339169d520dde91654938c1bd21400e65e003dcfc37df
|
|
| MD5 |
29ef6f81b5b29d1f46cad2d15289a3d1
|
|
| BLAKE2b-256 |
4bc2f7f71e3a145507d752a4fd8799b790e62a02da4ef5efd91413052d5f2b93
|