cf-json
Expanded JSON serialization
Summary
cf-json provides a batteries included approach to extending the standard json module.
It achieves this by making use of a custom json.JSONEncoder subclass cfjson.MyEncoder to expand the range of types that can be serialized. While keeping sticking to the json interface.
Installation
Install the package from PyPI:
$ python -m pip install cf-json
[...]
Successfully installed cf-json
Quick Start
cf-json is a drop in replacement for the standard json module.
>>> from cfjson import dumps, loads
>>> data = {1: 'a', 2: Path('./my_file.py'), 3: datetime.datetime.utcnow()}
>>> data
{1: 'a', 2: WindowsPath('my_file.py'), 3: datetime.datetime(2021, 4, 7, 2, 45, 57, 696066)}
>>> json_blob = dumps(data)
>>> json_blob
'{"1": "a", "2": {"__json_type__": "WindowsPath", "path": "my_file.py"}, "3": {"__json_type__": "datetime", "datetime": "2021-04-07T02:45:57.696066"}}'
>>> loads(json_blob)
{'1': 'a', '2': WindowsPath('my_file.py'), '3': datetime.datetime(2021, 4, 7, 2, 45, 57, 696066)}
Documentation
Metadata
Release files for cf-json 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cf-json-0.1.0.tar.gz | 9.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cf_json-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 MB
Release files / cf-json-0.1.0.tar.gz
| Download URL | cf-json-0.1.0.tar.gz |
|---|---|
| Size | 9.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9cc0aefae5904f4cfd11a32b48b693f70c5d04fd804643c78c0dd94dc4974d5c
|
|
BLAKE2b-256 checksum How to use checksums |
110bdb101ea9eafb9b67b62b06c927e6eccb8eabb765a47b487e64c5d6b16cb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.9 Linux/5.10.21-Unraid
|
Release files / cf_json-0.1.0-py3-none-any.whl
| Download URL | cf_json-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d35ed503a27844cdb4469ab64988ae65de6509a602be3002643d2ee31bcc96d6
|
|
BLAKE2b-256 checksum How to use checksums |
61432e6c8901a6bf09eef8a6a660bd3d24033f9dd7bd3b02f56930e0d96ee6bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.9 Linux/5.10.21-Unraid
|