Skip to main content

Utility for evaluate matching json with a template

Project description

Validation schema based of a json string or a dict

Schema:

  • You must define a dict which will match with a json/dict under test
  • add ! at begin fo key for to indicate a required field
  • In value of that key you will need specify a validator for such field
  • That validator have to be a valid default validator or you can add your own
    EXAMPLE_SCHEMA = {
        "!version": "string",
        "!email": "email",
        "!data": {
            "!Id": "number",
            "title": "string"  # optional
            },
        }

Usage:

Example:
    ok_json = {
        "version": "1.0.1a",
        "email": "test@test.com",
        "data": {
            "Id": 231,
            "title": "description"
        }
    }
    e = JSONEvaluator()
    e.set_schema(EXAMPLE_SCHEMA)
    e.evaluate(ok_json)
    if e.ok:
       print("Dict validate")
    else:
       print("errors found:")
       print(e.errors)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_pattern_validator-0.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

json_pattern_validator-0.1-py3-none-any.whl (5.1 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