jsonschema-validator-new


Namejsonschema-validator-new JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/sbrunner/jsonschema-validator
SummaryTool to validate files against a JSON Schema
upload_time2024-11-08 14:25:48
maintainerNone
docs_urlNone
authorStéphane Brunner
requires_python>=3.9
licenseBSD-2-Clause
keywords jsonschema types
VCS
bugtrack_url
requirements poetry pip poetry-dynamic-versioning poetry-plugin-export poetry-plugin-tweak-dependencies-version poetry-plugin-drop-python-upper-constraint
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JSON Schema validator

Tools to generate Python types based on TypedDict from a JSON schema

## Quick start

install:

```bash
python3 -m pip install jsonschema-validator-new
```

Convert a JSON schema to a Python file contains the types:

```bash
jsonschema-validator --help
```

## Default

The default values are exported in the Python file, then you can do something like that:

```python
value_with_default = my_object.get('field_name', my_schema.FIELD_DEFAULT)
```

## Validation

This package also provide some validations features for YAML file based on `jsonschema`.

Additional features:

- Obtain the line and columns number in the errors, if the file is loaded with `ruamel.yaml`.
- Export the default provided in the JSON schema.

```python
import ruamel.yaml
import pkgutil
import jsonschema_validator
import json

schema_data = pkgutil.get_data("<package>", "schema.json")
schema = json.loads(jsonschema_validator)
with open(filename) as data_file:
    yaml = ruamel.yaml.YAML()  # type: ignore
    data = yaml.load(data_file)
errors, _ = jsonschema_validator.validate(filename, data, schema)
if errors:
    print("\n".join(errors))
    sys.exit(1)
```

## Pre-commit hooks

This project provides pre-commit hooks to automatically generate the files.

```yaml
repos:
  - repo: https://github.com/camptocamp/jsonschema-validator
    rev: <version> # Use the ref you want to point at
    hools:
      - id: jsonschema-validator
        files: |
          (?x)^(
              ...
          )$
```

## Contributing

Install the pre-commit hooks:

```bash
pip install pre-commit
pre-commit install --allow-missing-config
```

The `prospector` tests should pass.

The code should be typed.

The code should be tested with `pytests`.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sbrunner/jsonschema-validator",
    "name": "jsonschema-validator-new",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "jsonschema, types",
    "author": "St\u00e9phane Brunner",
    "author_email": "stephane.brunner@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c6/d5/ed89f08eaa4bf821559a6b2ad79ef32c1186b8a950507e7bd4b1508d5688/jsonschema_validator_new-0.3.2.tar.gz",
    "platform": null,
    "description": "# JSON Schema validator\n\nTools to generate Python types based on TypedDict from a JSON schema\n\n## Quick start\n\ninstall:\n\n```bash\npython3 -m pip install jsonschema-validator-new\n```\n\nConvert a JSON schema to a Python file contains the types:\n\n```bash\njsonschema-validator --help\n```\n\n## Default\n\nThe default values are exported in the Python file, then you can do something like that:\n\n```python\nvalue_with_default = my_object.get('field_name', my_schema.FIELD_DEFAULT)\n```\n\n## Validation\n\nThis package also provide some validations features for YAML file based on `jsonschema`.\n\nAdditional features:\n\n- Obtain the line and columns number in the errors, if the file is loaded with `ruamel.yaml`.\n- Export the default provided in the JSON schema.\n\n```python\nimport ruamel.yaml\nimport pkgutil\nimport jsonschema_validator\nimport json\n\nschema_data = pkgutil.get_data(\"<package>\", \"schema.json\")\nschema = json.loads(jsonschema_validator)\nwith open(filename) as data_file:\n    yaml = ruamel.yaml.YAML()  # type: ignore\n    data = yaml.load(data_file)\nerrors, _ = jsonschema_validator.validate(filename, data, schema)\nif errors:\n    print(\"\\n\".join(errors))\n    sys.exit(1)\n```\n\n## Pre-commit hooks\n\nThis project provides pre-commit hooks to automatically generate the files.\n\n```yaml\nrepos:\n  - repo: https://github.com/camptocamp/jsonschema-validator\n    rev: <version> # Use the ref you want to point at\n    hools:\n      - id: jsonschema-validator\n        files: |\n          (?x)^(\n              ...\n          )$\n```\n\n## Contributing\n\nInstall the pre-commit hooks:\n\n```bash\npip install pre-commit\npre-commit install --allow-missing-config\n```\n\nThe `prospector` tests should pass.\n\nThe code should be typed.\n\nThe code should be tested with `pytests`.\n\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "Tool to validate files against a JSON Schema",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/sbrunner/jsonschema-validator",
        "Repository": "https://github.com/sbrunner/jsonschema-validator"
    },
    "split_keywords": [
        "jsonschema",
        " types"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d093d1810ebd3594c3cadbf6db26a16425e4b6247fa517f9a7f91bb869d9a6cf",
                "md5": "24d6c000a28c379bc201707a456c8b3b",
                "sha256": "1b18a2b2a6115c00ec879d2dc6f99fc657f1086f62b0abef1484165ff19b1b8d"
            },
            "downloads": -1,
            "filename": "jsonschema_validator_new-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "24d6c000a28c379bc201707a456c8b3b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7572,
            "upload_time": "2024-11-08T14:25:47",
            "upload_time_iso_8601": "2024-11-08T14:25:47.090635Z",
            "url": "https://files.pythonhosted.org/packages/d0/93/d1810ebd3594c3cadbf6db26a16425e4b6247fa517f9a7f91bb869d9a6cf/jsonschema_validator_new-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6d5ed89f08eaa4bf821559a6b2ad79ef32c1186b8a950507e7bd4b1508d5688",
                "md5": "dc77090f417f90bb9241a9ce835d1e11",
                "sha256": "622a93406d7ebc14ab40f54f83688ccbf0ee37acf81b9543c82914c5077555ba"
            },
            "downloads": -1,
            "filename": "jsonschema_validator_new-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "dc77090f417f90bb9241a9ce835d1e11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6850,
            "upload_time": "2024-11-08T14:25:48",
            "upload_time_iso_8601": "2024-11-08T14:25:48.824689Z",
            "url": "https://files.pythonhosted.org/packages/c6/d5/ed89f08eaa4bf821559a6b2ad79ef32c1186b8a950507e7bd4b1508d5688/jsonschema_validator_new-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-08 14:25:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sbrunner",
    "github_project": "jsonschema-validator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "poetry",
            "specs": [
                [
                    "==",
                    "1.8.4"
                ]
            ]
        },
        {
            "name": "pip",
            "specs": [
                [
                    "==",
                    "24.3.1"
                ]
            ]
        },
        {
            "name": "poetry-dynamic-versioning",
            "specs": [
                [
                    "==",
                    "1.4.1"
                ]
            ]
        },
        {
            "name": "poetry-plugin-export",
            "specs": [
                [
                    "==",
                    "1.8.0"
                ]
            ]
        },
        {
            "name": "poetry-plugin-tweak-dependencies-version",
            "specs": [
                [
                    "==",
                    "1.5.2"
                ]
            ]
        },
        {
            "name": "poetry-plugin-drop-python-upper-constraint",
            "specs": [
                [
                    "==",
                    "0.1.0"
                ]
            ]
        }
    ],
    "lcname": "jsonschema-validator-new"
}
        
Elapsed time: 0.45738s