Utilities for working with JSON Schema.
Project description
jsonschematools
Description
jsonschematools
is a Python library that provides utilities for working with JSON Schema. It includes features for adding and updating enums in the $defs
section of a JSON schema, and updating a property of a JSON schema with an existing enum reference.
Installation
To install jsonschematools
, you can use pip:
pip install jsonschematools
Usage
Here is a basic example of how to use jsonschematools
:
from jsonschematools.enums import add_or_update_enum_in_defs, update_property_with_enum
# Define a basic schema
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"tags": {"type": "array", "items": {"type": "string"}},
},
"$defs": {},
}
# Add a new enum to the schema
schema = add_or_update_enum_in_defs(schema, "Colors", ["Red", "Blue", "Green"])
# schema now looks like this:
# {
# "type": "object",
# "properties": {
# "name": {
# "type": "string"
# },
# "tags": {
# "type": "array",
# "items": {
# "type": "string"
# }
# }
# },
# "$defs": {
# "Colors": {
# "type": "string",
# "enum": [
# "Red",
# "Blue",
# "Green"
# ]
# }
# }
# }
# Update a property with the new enum
schema = update_property_with_enum(schema, "Colors", "tags")
# schema now looks like this:
# {
# "type": "object",
# "properties": {
# "name": {
# "type": "string"
# },
# "tags": {
# "type": "array",
# "items": {
# "$ref": "#/$defs/Colors"
# }
# }
# },
# "$defs": {
# "Colors": {
# "type": "string",
# "enum": [
# "Red",
# "Blue",
# "Green"
# ]
# }
# }
# }
Testing
Tests are written using pytest. To run the tests, use the following command:
pytest
Contributing
Contributions are welcome! Please fork the repository and create a pull request with your changes.
License
jsonschematools
is licensed under the MIT License.
Contact
For any questions or concerns, please open an issue on GitHub.
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 jsonschematools-0.2.0.tar.gz
.
File metadata
- Download URL: jsonschematools-0.2.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef1b0fc071c7633f9f4b9a313a1e31cf08ce698efc860c68e4c12875c5b05277 |
|
MD5 | 68e515de2dd5e57cecf44d9ff566123e |
|
BLAKE2b-256 | 203c4587670ac66730adb471600869f2c6cbf183a1e1c13aee1ba75fd6109800 |
File details
Details for the file jsonschematools-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: jsonschematools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a9cd88a96631f653611d9aa36b1d4277e04998c9f620a1c146af3cc28e3ad03 |
|
MD5 | 2ed6e70efe6ac727accd1c1b6a6283ce |
|
BLAKE2b-256 | 405f94c949447c8b5420ed95e9ec45f30735c807cfcd7c77fb37631c3a61b3a9 |