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.1.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.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonabc-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 3fa20c4958bcea65074786e8c8295b0793f510eb97e77312532455770f864bf4
MD5 96546cec9752bce87e817f37cafc6772
BLAKE2b-256 d65f3578a69b3116240c4689abd576d27c7e92a462f9c393be8f1edfcde464a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonabc-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61a79fa4a47601db093256c79f02517df1e3b28d667ad9c4617e9503afdeedb0
MD5 3cd32183164c31b5fc8ce819807bc4df
BLAKE2b-256 3e6611f918f5f6fc332c9e8d45a60995d9c29a8db253b07faca565f485ad2cf2

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