Skip to main content

A Python DSL for defining JSON schemas

Project description

Build Status Coverage

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

BSD license

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

jsl-0.0.6.tar.gz (9.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page