Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gregorybchris/jsonvl
Schema validation for JSON in Python
https://github.com/gregorybchris/jsonvl
json json-validation python schema validation
Last synced: about 1 month ago
JSON representation
Schema validation for JSON in Python
- Host: GitHub
- URL: https://github.com/gregorybchris/jsonvl
- Owner: gregorybchris
- License: apache-2.0
- Created: 2021-02-15T09:19:40.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-17T03:28:55.000Z (about 3 years ago)
- Last Synced: 2024-11-11T14:58:11.033Z (about 1 month ago)
- Topics: json, json-validation, python, schema, validation
- Language: Python
- Homepage:
- Size: 198 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
# JsonVL
[![GitHub CI](https://github.com/gregorybchris/jsonvl/workflows/JsonVL-CI/badge.svg?branch=main)](https://github.com/gregorybchris/jsonvl/actions?query=workflow%3AJsonVL-CI)
[![codecov](https://codecov.io/gh/gregorybchris/jsonvl/branch/main/graph/badge.svg?token=S8VQAMZ2OP)](https://codecov.io/gh/gregorybchris/jsonvl)JsonVL is a JSON validator for Python. This project is intended to be a replacement for the [jsonschema package](https://pypi.org/project/jsonschema/) which implements the [JSON Schema standard](https://json-schema.org/). JsonVL's goal is to curate a rich set of validation methods for JSON data types while remaining extensible to new constraints.
## Installation
Install the latest [PyPI release](https://pypi.org/project/jsonv/):
```bash
pip install jsonvl
```## Usage
### Validate JSON files from the command line
```bash
jsonvl data.json schema.json
```### Validate JSON files in Python
```python
from jsonvl import validate_filevalidate_file('data.json', 'schema.json')
```### Validate in-memory JSON data in Python
```python
from jsonvl import validatevalidate(data, schema)
```## Documentation
The JsonVL documentation is hosted by [Read the Docs](https://jsonvl.readthedocs.io) and is a work in progress.
## Example
Below is an example pair of JSON data and JSON schema. More examples can be found in the [examples](https://github.com/gregorybchris/jsonvl/tree/main/examples) folder.
### Data
```json
{
"play": "A Midsummer Night's Dream",
"characters": [
{ "name": "Helena", "loves": ["Demitrius"] },
{ "name": "Demitrius", "loves": ["Hermia", "Helena"] },
{ "name": "Hermia", "loves": ["Lysander"] },
{ "name": "Lysander", "loves": ["Hermia", "Helena", "Hermia"] },
{ "name": "Titania", "loves": ["Oberon", "Bottom", "Oberon"] },
{ "name": "Oberon", "loves": ["Titania"] },
{ "name": "Bottom", "loves": [] },
{ "name": "Puck", "loves": [] }
]
}
```### Schema
```json
{
"type": "object",
"attr": {
"play": "string",
"characters": {
"type": "array",
"cons": {
"unique": "@all.name"
},
"elem": {
"type": "object",
"attr": {
"name": "#name",
"loves": {
"type": "array",
"elem": "#name",
"cons": { "max_size": 4 }
}
}
}
}
},
"defs": {
"#name": {
"type": "string",
"cons": {
"format": { "type": "regex", "pattern": "[A-Z][a-z]{0,10}" }
}
}
}
}
```