Skip to main content

A Python DSL for defining JSON schemas

Project description

Build Status Coverage PyPI Version PyPI Downloads

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.9.tar.gz (12.3 kB view details)

Uploaded Source

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

Hashes for jsl-0.0.9.tar.gz
Algorithm Hash digest
SHA256 d5eb66648476635e45e21da3f9706ea3c8ecd14c7539c639d85bd15077656907
MD5 f74c15ebb8db6d8f35f6407a3a03a3e9
BLAKE2b-256 5b5468d971f33f533c9f07b75b3ffa30be04cd2d6f7fac1fc31980e97ccd4b3f

See more details on using hashes here.

Provenance

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