vjson creates an object to serialize the only of the type specified in JSONSchema. It works like a json module.
Project description
vjson
0.1.0
vjson creates an object to serialize the only of the type specified in JSONSchema. It works like a json module.
install
Next, execute command.:
$ pip install vjson
How to use
You define an object using JSONSchema.:
>>> import vjson
>>> _json = vjson.ValidatedJSON({
... 'type': 'object',
... 'properties': {
... 'price': {'type': 'number'},
... 'name': {'type': 'string'},
... },
... })
This object can dumps/loads()/dump()/load() the serializable object, as in the json module.:
>>> _json.loads('{"name" : "Eggs", "price" : 34.99}')
{'name': 'Eggs', 'price': 34.99}
>>> _json.dumps({"name": "Eggs", "price": 34.99})
'{"name": "Eggs", "price": 34.99}'
If you try to pass the data that violates the JSONSchema that was specified in the constructor, it raises a vjson.JSONValidationError.:
>>> _json.loads('{"name" : "Eggs", "price" : "34.99"}')
Traceback (most recent call last):
File "/tmp/test/var/src/develop/vjson/src/vjson/__init__.py", line 32, in _wrap
jsonschema.validate(data, schema)
File "/tmp/test/env/lib/python3.4/site-packages/jsonschema/validators.py", line 478, in validate
cls(schema, *args, **kwargs).validate(instance)
File "/tmp/test/env/lib/python3.4/site-packages/jsonschema/validators.py", line 123, in validate
raise error
jsonschema.exceptions.ValidationError: '34.99' is not of type 'number'
Failed validating 'type' in schema['properties']['price']:
{'type': 'number'}
On instance['price']:
'34.99'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/test/var/src/develop/vjson/src/vjson/__init__.py", line 34, in _wrap
raise JSONValidationError(err)
vjson.JSONValidationError: '34.99' is not of type 'number'
Failed validating 'type' in schema['properties']['price']:
{'type': 'number'}
On instance['price']:
'34.99'
>>>
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 vjson-0.1.tar.gz.
File metadata
- Download URL: vjson-0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84cf1f2e293fda30c255dcd338d1492822c478fbb00f162a0e5265b8863e818a
|
|
| MD5 |
5ff5576be60ab1e54d5af27c2ca70926
|
|
| BLAKE2b-256 |
e1283e0c609365ca5e6dd2d83e8d176a8393f09d22f51f53a02bbb847cc912c6
|
File details
Details for the file vjson-0.1-py3-none-any.whl.
File metadata
- Download URL: vjson-0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcfdaaba3ea858a096bdba68cdeaba7b0197b0514b07b796c2fc79ff93af914a
|
|
| MD5 |
1aead9ce2c8a9b47c76a9ebf7d30e299
|
|
| BLAKE2b-256 |
4a495a0d31034da153362f9209752757819812f618d96fa527695140912f936a
|