Skip to main content

JSON schema validator.

Project description

JsonVL

GitHub CI codecov

JsonVL is a JSON validator for Python. This project is intended to be a replacement for the jsonschema package which implements the JSON Schema standard. JsonVL's goal is to curate a rich set of validation methods for JSON data types while remaining extensible to new constraints.

Installation

Install the latest PyPI release:

pip install jsonvl

Usage

Validate JSON files from the command line

jsonvl data.json schema.json

Validate JSON files in Python

from jsonvl import validate_file

validate_file('data.json', 'schema.json')

Validate in-memory JSON data in Python

from jsonvl import validate

validate(data, schema)

Documentation

The JsonVL documentation is hosted by Read the Docs and is a work in progress.

Example

Below is an example pair of JSON data and JSON schema. More examples can be found in the examples folder.

Data

{
  "play": "A Midsummer Night's Dream",
  "characters": [
    { "name": "Helena", "loves": ["Demitrius"] },
    { "name": "Demitrius", "loves": ["Hermia", "Helena"] },
    { "name": "Hermia", "loves": ["Lysander"] },
    { "name": "Lysander", "loves": ["Hermia", "Helena", "Hermia"] },
    { "name": "Titania", "loves": ["Oberon", "Bottom", "Oberon"] },
    { "name": "Oberon", "loves": ["Titania"] },
    { "name": "Bottom", "loves": [] },
    { "name": "Puck", "loves": [] }
  ]
}

Schema

{
  "type": "object",
  "attr": {
    "play": "string",
    "characters": {
      "type": "array",
      "cons": {
        "unique": "@all.name"
      },
      "elem": {
        "type": "object",
        "attr": {
          "name": "#name",
          "loves": {
            "type": "array",
            "elem": "#name",
            "cons": { "max_size": 4 }
          }
        }
      }
    }
  },
  "defs": {
    "#name": {
      "type": "string",
      "cons": {
        "format": { "type": "regex", "pattern": "[A-Z][a-z]{0,10}" }
      }
    }
  }
}

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

jsonvl-0.5.0.tar.gz (18.7 kB view hashes)

Uploaded Source

Built Distribution

jsonvl-0.5.0-py3-none-any.whl (28.3 kB view hashes)

Uploaded Python 3

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