A thin wrapper over to allow validating schemas easily using simple CLI commands.
Project description
This is based on the frok from jsonschema-cli.
JsonSchema CLI
A thin wrapper over Python Jsonschema to allow validating shcemas easily using simple CLI commands.
Installing
pip install jsonschema-cli2
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:
- When using this tool in a backend server, make sure the file access is scoped.
- Don't run JSONSCHEMAS without sanitizing paths.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jsonschema_cli2-1.3.2.tar.gz
.
File metadata
- Download URL: jsonschema_cli2-1.3.2.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0ec8f7ffb23e4ca90c53940a96acee40ecf2c548168152482d1233da808df2 |
|
MD5 | cd25d2a60781b23a57b9f49414ba9de8 |
|
BLAKE2b-256 | 721c2650b96e9215fe8230c88b5e879cc5cd777e546ec31a3411ee17112ba92b |
File details
Details for the file jsonschema_cli2-1.3.2-py3-none-any.whl
.
File metadata
- Download URL: jsonschema_cli2-1.3.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fdda1f155ae520efb87b5568016078342ac46fa8efda72dd81b8de323ab6e85 |
|
MD5 | cf051b21f659382aa5cd337ff96f3f7c |
|
BLAKE2b-256 | 047f69c41aa2e440ac014a55df9476a8d20fd3bdb86cde8bbb3610ee45404865 |