JSON with extensions to support serialization for common types
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cf-json-0.1.0.tar.gz
(9.2 MB
view details)
Built Distribution
File details
Details for the file cf-json-0.1.0.tar.gz
.
File metadata
- Download URL: cf-json-0.1.0.tar.gz
- Upload date:
- Size: 9.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.9 Linux/5.10.21-Unraid
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc0aefae5904f4cfd11a32b48b693f70c5d04fd804643c78c0dd94dc4974d5c |
|
MD5 | f763c8f8cd3abd871204f4180fefc5d7 |
|
BLAKE2b-256 | 110bdb101ea9eafb9b67b62b06c927e6eccb8eabb765a47b487e64c5d6b16cb6 |
File details
Details for the file cf_json-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: cf_json-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.9 Linux/5.10.21-Unraid
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d35ed503a27844cdb4469ab64988ae65de6509a602be3002643d2ee31bcc96d6 |
|
MD5 | 94906d2d90894923bc0f8906a021a2fe |
|
BLAKE2b-256 | 61432e6c8901a6bf09eef8a6a660bd3d24033f9dd7bd3b02f56930e0d96ee6bb |