Easy JSON Validator
Description
A python package for deep json validation easy to use and well explained
Install
pip install easy-validator
Usage example
Success Case
from easyvalidator import JsonValidator
source = {"name": "My Name", "birth": "2000-01-01", "salary": 1000} # your json
template = {"name": ["NotNull"]} # what you want to test
validator = JsonValidator(template=template, source=source)
result = validator.validate()
print(f"result: {result}")
# result: {'name': {'value': "My Name", 'rules': ['NotNull'], 'validations': {'NotNull': {'status': 'OK'}}}}
Fail Case
from easyvalidator import JsonValidator
source = {"name": null, "birth": "2000-01-01", "salary": 1000} # your json
template = {"name": ["NotNull"]} # what you want to test
validator = JsonValidator(template=template, source=source)
result = validator.validate()
print(f"result: {result}")
# result: {'name': {'value': "My Name", 'rules': ['NotNull'], 'validations': {'NotNull': {'status': 'FAIL', 'msg': 'Field can not be null'}}}}
More Complex Case with deep field validation
from easyvalidator import JsonValidator
source = {"name": "My Name", "birth": "2000-01-01", "salary": 1000, "address": {"details": "number": 13}} # your json
template = {"address": {"details": "number": ["GreaterThan(value=12)", "IsBetween(start=10, end=20)"]}} # what you want to test
validator = JsonValidator(template=template, source=source)
result = validator.validate()
print(f"result: {result}")
# result: {"address": {"details": "number": {'value': 13, 'rules': ['GreaterThan(value=12)', 'IsBetween(start=10, end=20)'], 'validations': {'GreaterThan(value=12)': {'status': 'OK'}, IsBetween(start=10, end=20)': {'status': 'OK'}}}}
Available Rules
NotNull
NotEmpty
IsEmpty
NotEquals(value=VALUE)
IsBetween(start=NUMERICAL VALUE, end=NUMERICAL VALUE)
IsNotBetween(start=NUMERICAL VALUE, end=NUMERICAL VALUE)
DateIsAfter(date=YYYY-mm-dd)
DateIsBefore(date=YYYY-mm-dd)
DateIsExactly(date=YYYY-mm-dd)
GreaterThan(value=NUMERICAL VALUE)
LessThan(value=NUMERICAL VALUE)
LessThanOrEqual(value=NUMERICAL VALUE)
GreaterThanOrEqual(value=NUMERICAL VALUE)
TextEquals(value=VALUE)
TextContains(value=VALUE)
TextNotContains(value=VALUE)
TextStartsWith(value=VALUE)
TextEndsWith(value=VALUE)
Source Code
Author
Metadata
Release files for easy-validator 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easy-validator-0.0.1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_validator-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / easy-validator-0.0.1.tar.gz
| Download URL | easy-validator-0.0.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b07384fa52b80304724d89ca36357972e53fe5fe0552ed9e77f6c69945a50c3f
|
|
BLAKE2b-256 checksum How to use checksums |
f57498057bed3a87762e543c29c9c72f31d3b4d18e18766e297f1a11a860a69d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3
|
Release files / easy_validator-0.0.1-py3-none-any.whl
| Download URL | easy_validator-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7f9f5470a2f1263d9341f80a63e6f3699358b97275f8d1f7cce780dae832636
|
|
BLAKE2b-256 checksum How to use checksums |
cae2616bb04eb36a651cf98b8c740f5652cd1ec160cca8ccb0eb5dff6fc4c94f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3
|