Skip to main content

JSON validator.

Project description

jsonvl

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 constraints for JSON data types while remaining extensible to arbitrary data constraints.

Note: This package is a work in progress and contributions are welome.

Installation

Install the current PyPI release:

pip install jsonvl

Usage

Validate JSON from the command line

jsonvl data.json schema.json

Validate JSON in Python

from jsonvl import validate_file

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

Roadmap

  • JSON data type checking
    • Number, string, boolean, and null primitives
    • Array and object collections
  • Number constraints
    • lt
    • gt
    • eq
  • String constraints
    • in
    • eq
    • format
      • regex
      • phone
      • email
  • Array constraints
    • max_size
    • min_size
    • unique
  • Path traversal for multi-level constraints
  • Quantifiers for array traversal
  • Type definitions and references
  • Conditional validation
  • Union types (including nullable)
  • Custom constraints

Example

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",
  "attrs": {
    "play": "string",
    "characters": {
      "type": "array",
      "cons": {
        "unique": "@all.name"
      },
      "elem": {
        "type": "object",
        "attrs": {
          "name": {
            "type": "string",
            "cons": {
              "format": { "type": "regex", "pattern": "[A-Z][a-z]{0,10}" }
            }
          },
          "loves": {
            "type": "array",
            "elem": "string",
            "cons": { "max_size": 4 }
          }
        }
      }
    }
  }
}

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.0.1.tar.gz (13.8 kB view hashes)

Uploaded Source

Built Distribution

jsonvl-0.0.1-py3-none-any.whl (19.9 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