jsonvl

JSON schema validator.


Keywords
json, schema, validator, checker, types, typing, constraint, json-validation, validation
License
Apache-2.0
Install
pip install jsonvl==0.5.0

Documentation

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}" }
      }
    }
  }
}