Minimal, pythonic JSON to class serializer with zero dependencies and types validation.
Project description
JSONABC
Json Abstract Base Class
JSONABC is a minimal, pythonic JSON to class serializer. It has zero dependencies which makes it very lightweight. It provide a very minimal API with few options and play nicely with python type checking.
Install
pip install jsonabc
Examples
example 1 (simple)
from jsonabc import JSONABC
# All you need to do is define JSONABC as your metaclass
class Response(metaclass=JSONABC):
args: dict
headers: dict
origin: str
url: str
resp = requests.get("https://httpbin.org/get")
json_data = resp.json()
# Your class can now take a single dict and automatically validate and parse it.
obj = Response(response)
# obj attributes now have their correspondent values from our json data.
# you can also convert your class back to its json form.
# JSONABC will preserve the same names for the original json keys.
print(obj.json())
example 2 (composite)
from jsonabc import JSONABC
# You can also define composite values instead of using dicts
class Headers(metaclass=JSONABC):
accept: str
accept_encoding: str
class Response(metaclass=JSONABC):
args: dict
headers: Headers
origin: str
url: str
resp = requests.get("https://httpbin.org/get")
json_data = resp.json()
obj = Response(response)
# headers attr is now an instance of Headers with the same behavior as Response
obj.headers
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
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 jsonabc-0.0.3.tar.gz.
File metadata
- Download URL: jsonabc-0.0.3.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
365a06ccb357748645e4392b2886b1902d1b07fe454ed1b0f11ca686ef0e9e21
|
|
| MD5 |
2b6c941bd5d6f9e3c02491194fdf3537
|
|
| BLAKE2b-256 |
81fc824917f8a2c3d8dff89d36260c4e9cdd588e0da6119e08896f816e91d5cc
|
File details
Details for the file jsonabc-0.0.3-py3-none-any.whl.
File metadata
- Download URL: jsonabc-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ca665ec2142a714e8d8add173e9c8bdcc77c5b7a4b39bee5c45a8d2bd7f56de
|
|
| MD5 |
e1911ce4f51773b255bdf703d3765280
|
|
| BLAKE2b-256 |
471eb0ea6803bcd669f347453c104365b243339c5cc0d33ca8ea41f740dd6a93
|