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.0.3.dev1.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for cf_json-0.0.3.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1df53886a41fe430c88c9f57febd593dfff8d8d0769447fa3a1c9f7892c143ef |
|
MD5 | b9030190afa348c0578381f4b0f3fe44 |
|
BLAKE2b-256 | 508bac9016fade11b7357b35c6be6f95c9a582896a63e88ce9ea0f8893a901d4 |