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

Uploaded Source

File details

Details for the file jsl-0.0.8.tar.gz.

File metadata

  • Download URL: jsl-0.0.8.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsl-0.0.8.tar.gz
Algorithm Hash digest
SHA256 8967c959eb7c6685039e503be16f842985af150d593a3e25e23a0d65c5ca7a0c
MD5 7e88930cb4ec48ac41ea83817c892351
BLAKE2b-256 53c4d9ecfe01eb576e3f036f11d4117d0ebc3d8a88a7c4c04680ebad230b2d91

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