Skip to main content

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 

TODO

  • Add Spec Testing
  • json() to preserve original json keys.

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

jsonabc-0.0.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonabc-0.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file jsonabc-0.0.2.tar.gz.

File metadata

  • Download URL: jsonabc-0.0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for jsonabc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c23b4c305ce746e7365c35f6adca74fcff035649266711fbaaa5728a4e12e566
MD5 8a84f8ec0ce44043dcf0928f1c3927cf
BLAKE2b-256 9e7b6654eee132f3db7b37da94efd1b1a5db9607dd81298606eabc7c56209c62

See more details on using hashes here.

File details

Details for the file jsonabc-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: jsonabc-0.0.2-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.9.6

File hashes

Hashes for jsonabc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 720b9d37ca395bc9c1a710f4a073ede3e4c4589ff4e6392bca3a907d301e858c
MD5 8cc003f87381da3ebd9109b4709ab7fa
BLAKE2b-256 2b8a283921f3637b712954663c78cadb3d2e8e31b212429922bc8547da94520f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page