Skip to main content

A Python DSL for defining JSON schemas

Project description

Build Status Coverage Documentation PyPI Version PyPI Downloads

Documentation | GitHub | PyPI

JSL is a Python DSL for defining JSON Schemas.

Example

import jsl

class Entry(jsl.Document):
    name = jsl.StringField(required=True)

class File(Entry):
    content = jsl.StringField(required=True)

class Directory(Entry):
    content = jsl.ArrayField(jsl.OneOfField([
        jsl.DocumentField(File, as_ref=True),
        jsl.DocumentField(jsl.RECURSIVE_REFERENCE_CONSTANT)
    ]), required=True)

Directory.get_schema(ordered=True) will return the following JSON schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "directory": {
            "type": "object",
            "properties": {
                "name": {"type": "string"},
                "content": {
                    "type": "array",
                    "items": {
                        "oneOf": [
                            {"$ref": "#/definitions/file"},
                            {"$ref": "#/definitions/directory"}
                        ]
                    }
                }
            },
            "required": ["name", "content"],
            "additionalProperties": false
        },
        "file": {
            "type": "object",
            "properties": {
                "name": {"type": "string"},
                "content": {"type": "string"}
            },
            "required": ["name", "content"],
            "additionalProperties": false
        }
    },
    "$ref": "#/definitions/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.1.1.tar.gz (19.5 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for jsl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f12fcf6022ebb5ba35fdfd06a6354d94d474fcd1fdd48cfe193d62a2afa7de31
MD5 1421b528e15bb814b7c92ddab62332fc
BLAKE2b-256 ab658a4b4d1e7d5356ce3446c6a12efa211c8cbb46ab6afc9eda415f3aeaed1a

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