Skip to main content

A pre-commit hook for validating files against jsonschemas.

Project description

check-jsonschema

A pre-commit hook for checking files against a JSONSchema, built using the python jsonschema package. The schema may be specified as a local or remote (HTTP or HTTPS) file.

Remote files are automatically downloaded and cached if possible.

Supported Hooks

The most generic hook is this one:

  • check-jsonschema: Validate JSON or YAML files against a jsonschema on disk or fetched via HTTP(S)

These hooks check known files against schemas provided by Schemastore:

  • check-github-workflows: Validate GitHub Workflows in .github/workflows/

  • check-github-actions: Validate GitHub Actions in .github/actions/ or the action.yml at the repo root

  • check-travis: Validate Travis config

These hooks check known files against schemas provided by other sources:

  • check-azure-pipelines: Validate Azure Pipelines config against the schema provided by Microsoft

Example Usage

Validate GitHub Workflows with Schemastore

You can use the schemastore github workflow schema to lint your GitHub workflow files. All you need to add to your .pre-commit-config.yaml is this:

- repo: https://github.com/sirosen/check-jsonschema
  rev: 0.6.0
  hooks:
    - id: check-github-workflows

Applying an arbitrary schema to files

There is a more general hook available for running any jsonschema against a file or set of files. For example, to implement the GitHub workflow check manually, you could do this:

- repo: https://github.com/sirosen/check-jsonschema
  rev: 0.6.0
  hooks:
    - id: check-jsonschema
      name: "Check GitHub Workflows"
      language: python
      files: ^\.github/workflows/
      types: [yaml]
      args: ["--schemafile", "https://json.schemastore.org/github-workflow"]

Standalone Usage

You can also pip install check-jsonschema to run the tool manually.

For full usage info:

check-jsonschema --help

CLI Options

These options apply both to standalone usage and pre-commit hook usage.

--schemafile

The path or URL for a file containing a schema to use.

This option is required.

--no-cache

Do not cache HTTP(S) downloaded schemas.

--disable-format

JSON Schema defines a "format" attribute for string fields but does not require that any validation for formats be applied.

Starting in version 0.6.0, check-jsonschema will automatically check some formats by default. This flag disables these checks.

Because "format" checking is not done by all JSON Schema tools, it is possible that a file may validate under a schema with a different tool, but fail with check-jsonschema if --disable-format is not set.

--cache-filename

The name to use for caching a remote (HTTP or HTTPS) schema.

Defaults to using the last slash-delimited part of the URI.

--default-filetype

The default filetype to assume on instance files when they are detected neither as JSON nor as YAML.

For example, pass --default-filetype yaml to instruct that files which have no extension should be treated as YAML.

By default, this is not set and files without a detected type of JSON or YAML will fail.

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

check-jsonschema-0.7.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

check_jsonschema-0.7.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file check-jsonschema-0.7.0.tar.gz.

File metadata

  • Download URL: check-jsonschema-0.7.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for check-jsonschema-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e92b9be50b225eb69eeab2cd749ad7ca5b633cefe2debca9b958a4bb7e5719a6
MD5 b6434fda415d701de2178d29f7ccc218
BLAKE2b-256 c34f97d25e9e30dda27f72d4ebcb730251d6560beed14eae77ede55b7b34e837

See more details on using hashes here.

Provenance

File details

Details for the file check_jsonschema-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: check_jsonschema-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for check_jsonschema-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f733e5cc45ef1107393c36cb09731a7c319cca313044f6ed30054b632f19711
MD5 f1454b32fe5df14154b382e2e66ae148
BLAKE2b-256 608b8bf17567aa148c7e65b4584e7ffc3d95d8e4edabf24cb5bbe6d1f830f0b7

See more details on using hashes here.

Provenance

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