Type declaration and validation library for JSON
Project description
jsonene
This library is intended to provide APIs to define JSON schema, create instances from schema, serialize/de-serialize to/from json or dict to Objects.
Inspired by
The basic idea is to provide light weight class based schema defination and data classes
Installation
pip install jsonene
Demos:
import enum
from pprint import pprint
import jsonene
class Gender(enum.Enum):
MALE = "Male"
FEMALE = "Female"
OTHER = "Other"
class Person(jsonene.ObjectType):
class Meta:
field_dependencies = [jsonene.RequiredDependency("age", ["date_of_birth"])]
age = jsonene.Integer(required=False)
name = jsonene.String()
country = jsonene.Const("India")
email = jsonene.Format(jsonene.Format.EMAIL)
contact = jsonene.String(required=False)
date_of_birth = jsonene.Format(jsonene.Format.DATE, required=False)
gender = jsonene.Enum(Gender)
ip = jsonene.Format(jsonene.Format.IPV4)
class Seller(Person):
brokerrage = jsonene.Integer(required=False)
is_broker = jsonene.AnyOf(True, False)
is_owner = jsonene.AnyOf(True, False)
# Nested schema
class House(jsonene.ObjectType):
owner = jsonene.Field(Person)
seller = jsonene.Field(Seller)
# Know your json-schema
pprint(Person.asField().json_schema)
owner = Person(
name="test",
age=30,
country="India",
email="conikhil@gmail.com",
gender=Gender.MALE.value,
date_of_birth="1989-09-11",
ip="10.8.9.0",
)
owner.validate(check_formats=True)
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
jsonene-0.1.0.tar.gz
(6.0 kB
view details)
File details
Details for the file jsonene-0.1.0.tar.gz.
File metadata
- Download URL: jsonene-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be54cf6f0f6ca048520f5c8be032a9f05f4f6c920fc1a164aaadf0909ad948e3
|
|
| MD5 |
8708fd8eedb5077cb1d9515858cf8d9d
|
|
| BLAKE2b-256 |
939b56a80a7d2ad8633526e092f13594f9e08dace428dfbf7add3ea430fcb077
|