Skip to main content

Validator class for Django model JSON fields.

Project description

Django JSON Schema Field Validator

https://app.travis-ci.com/chrislawlor/jsonfield-validation.svg?branch=master Documentation Status

JSON Schema validation for Django JSONField.

Quickstart

Installation

pip install jsonfield-validation

Usage

from jsonfield_validation import JsonSchemaValidator


class MyModel(models.Model):
    items = models.JSONField(
        validators=[
            JsonSchemaValidator({"maxItems": 2})
        ]
    )

Like any Django model field validator, validation happens when clean_fields() is called on a model instance:

>>> instance = MyModel(items=[1, 2, 3])
>>> instance.clean_fields()

django.core.exceptions.ValidationError: {'items': ["[1, 2, 3] is too long"]}

Further documentation is gratiously hosted by Read the Docs

Credits

This package was created with Cookiecutter and the pymetrics/cookiecutter-python-library project template.

History

0.3.0 (2022-06-15)

  • Add path to invalid value to error_list message,

0.2.0 (2022-06-15)

  • Add check method.

0.1.0 (2022-06-14)

  • First release on PyPI.

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

jsonfield_validation-0.3.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonfield_validation-0.3.0-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jsonfield_validation-0.3.0.tar.gz.

File metadata

  • Download URL: jsonfield_validation-0.3.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.0

File hashes

Hashes for jsonfield_validation-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ca63959d76d0b54cab904faa922cd7c93ba680e61bc051ee41dd873108fb123a
MD5 a07c5df6ba103aee09f17229059d0f6f
BLAKE2b-256 9076a5da1f3f7ee53daac40728765936ad130e235f0ea3b495a9743a47f42fde

See more details on using hashes here.

File details

Details for the file jsonfield_validation-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jsonfield_validation-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 077478c4ab292d4012e62c8f7cab06730297e023a72303cacf569b4cc47dc5ba
MD5 6e2f2ea9ecb9cfa780ecdee5a04090c9
BLAKE2b-256 9e15659127732e24cbd4f2460e7dda4f80c54f8d7a1881a7791888a87a2c38a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page