A Python DSL for defining JSON schemas
Project description
Documentation | GitHub | PyPI
JSL is a Python DSL for defining JSON Schemas.
Example
from jsl import Document, StringField, ArrayField, DocumentField, OneOfField
class Entry(Document):
name = StringField(required=True)
class File(Entry):
content = StringField(required=True)
class Directory(Entry):
content = ArrayField(OneOfField([
DocumentField(File, as_ref=True),
DocumentField('self') # recursion
]), required=True)
Directory.to_schema() will return the following schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"module.File": {
"type": "object",
"additionalProperties": false,
"required": [
"content",
"name"
],
"properties": {
"content": {"type": "string"},
"name": {"type": "string"}
}
},
"module.Directory": {
"type": "object",
"additionalProperties": false,
"required": [
"content",
"name"
],
"properties": {
"content": {
"type": "array",
"items": {
"oneOf": [
{"$ref": "#/definitions/module.File"},
{"$ref": "#/definitions/module.Directory"}
]
}
},
"name": {"type": "string"}
}
}
},
"$ref": "#/definitions/module.Directory"
}
Installing
pip install jsl
License
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
jsl-0.0.9.tar.gz
(12.3 kB
view details)
File details
Details for the file jsl-0.0.9.tar.gz
.
File metadata
- Download URL: jsl-0.0.9.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5eb66648476635e45e21da3f9706ea3c8ecd14c7539c639d85bd15077656907 |
|
MD5 | f74c15ebb8db6d8f35f6407a3a03a3e9 |
|
BLAKE2b-256 | 5b5468d971f33f533c9f07b75b3ffa30be04cd2d6f7fac1fc31980e97ccd4b3f |