Skip to main content

A thin wrapper over [Python Jsonschema](https://github.com/Julian/jsonschema) to allow validating shcemas easily using simple CLI commands.

Project description

JsonSchema CLI

A thin wrapper over Python Jsonschema to allow validating shcemas easily using simple CLI commands.

Installing

pip install jsonschema-cli

Security

The $ref resolving will automatically resolve to any path using basic $ref notation:

{"$ref": "my-custom.json#...."}

That means that when using this tool, an attacker may do the following:

{"$ref": "../../../../all-my-secrets.json"}

To make sure this doesn't happen:

  1. When using this tool in a backend server, make sure the file access is scoped.
  2. Don't run JSONSCHEMAS without sanitizing paths.
  3. Treat all un-knwon user input as evil.

This has no actual current affect other than loading the contets of secrets into memory of the process. But may lead to misfortune if not addressed.

Usgae

Using jsonschema-cli --help

usage: jsonschema-cli [-h] {validate} ...

A wrapper around https://github.com/Julian/jsonschema to validate JSON using the CLI

positional arguments:
  {validate}  Validate thet json data with a schema
    validate  Validate

optional arguments:
  -h, --help  show this help message and exit

Validate

Using jsonschema-cli validate --help

usage: jsonschema-cli validate [-h] schema_file_or_string data_file_or_string

positional arguments:
  schema_file_or_string
                        The schema you want to use to validate the data
  data_file_or_string   The data you want validated by the schema

optional arguments:
  -h, --help            show this help message and exit

Examples

# Returns no errors on stdout, no output needed on success (just exit code 0 is enough)
jsonschema-cli validate '{"properties": {"number": {"type": "integer"}}, "required": ["number"]}' '{"number": 123}'
# Has an error, "number" is now "123" instead of 123, an integer is expected.
jsonschema-cli validate '{"properties": {"number": {"type": "integer"}}, "required": ["number"]}' '{"number": "123"}'
> '123' is not of type 'integer'
>
> Failed validating 'type' in schema['properties']['number']:
>     {'type': 'integer'}
>
> On instance['number']:
>     '123'

Load YAML

The CLI command can read YAML and validate both schema and data written in YAML

# Returns no errors on stdout, no output needed on success (just exit code 0 is enough)
SCHEMA="
properties:
  number:
    type: integer
"
DATA="
number: 123
"
jsonschema-cli validate "$SCHEMA" "$DATA"
# Has an error, "number" is now "123" instead of 123, an integer is expected.
SCHEMA="
properties:
  number:
    type: integer
"
DATA="
number: \"123\"
"
jsonschema-cli validate "$SCHEMA" "$DATA"
> '123' is not of type 'integer'
>
> Failed validating 'type' in schema['properties']['number']:
>     {'type': 'integer'}
>
> On instance['number']:
>     '123'

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

jsonschema-cli-0.6.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

jsonschema_cli-0.6.2-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema-cli-0.6.2.tar.gz.

File metadata

  • Download URL: jsonschema-cli-0.6.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.6.10 Darwin/19.4.0

File hashes

Hashes for jsonschema-cli-0.6.2.tar.gz
Algorithm Hash digest
SHA256 acab001619d2e6d8ba363e3cb02d8fc31f43d8dd7318c96ada0674a7fde28aa3
MD5 e0491f5ed7db53f2afe7285743fdb6cd
BLAKE2b-256 5156acfde10650b1b11c0a9764c50ae5e17104d35c88194eca49362b61184892

See more details on using hashes here.

File details

Details for the file jsonschema_cli-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: jsonschema_cli-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.6.10 Darwin/19.4.0

File hashes

Hashes for jsonschema_cli-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 68641e87a6edd1524fc4eff885ca2bc62970dc5853a9bbf46f245bde20e4a4f0
MD5 ed2fdec0c5c9ee813d1e6b4f647eadb5
BLAKE2b-256 e992868c8107eacbcdc20a5e162314df24ff90adc5924278f45b5ed57e8b1164

See more details on using hashes here.

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