json-schema-parser
A Python library for converting between JSON schema definitions and Pydantic models.
Features
- Parse a JSON schema dict into a validated Pydantic model
- Generate a JSON schema dict from any Python type or Pydantic model
- Supports all common types:
integer,float,string,boolean,json,uuid,datetime - Supports list (
is_many) and optional (is_optional) variants of every type - Nested object schemas via
ComplexTypeInput
Installation
pip install json-schema-parser
Usage
Parse a JSON schema into a Pydantic model
from json_schema_parser import JsonSchemaParser
schema = {
"__config": {"field_type": "json", "is_many": False, "is_optional": False, "field_default_value": None, "description": ""},
"name": {"field_type": "string", "is_many": False, "is_optional": False, "field_default_value": None, "description": "User name"},
"age": {"field_type": "integer", "is_many": False, "is_optional": True, "field_default_value": None, "description": "User age"},
}
parser = JsonSchemaParser.model_validate(schema)
Model = parser.generate_pydantic_model("User")
user = Model.model_validate({"name": "Alice", "age": 30})
Generate a JSON schema from a Python type
from json_schema_parser import JsonSchemaParser
from pydantic import BaseModel
from typing import Optional, List
class Address(BaseModel):
street: str
city: str
schema = JsonSchemaParser.generate_json_schema_from_data_type(Address)
Supported field types
field_type value |
Python type |
|---|---|
"integer" |
int |
"float" |
float |
"string" |
str |
"boolean" |
bool |
"uuid" |
UUID |
"datetime" |
datetime |
"json" |
dict / nested model |
Set is_many: true to get a List[T], and is_optional: true to get Optional[T].
License
MIT
Metadata
Release files for json-schema-parser 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| json_schema_parser-1.0.2.tar.gz | 7.2 kB | Without provenance | Details for json_schema_parser-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_schema_parser-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for json_schema_parser-1.0.2-py3-none-any.whl |
Total release size: 15.0 kB
Release files / json_schema_parser-1.0.2.tar.gz
| Download URL | json_schema_parser-1.0.2.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
287cd0b1b45e1533debf48fefde72ab27b1dbe117bdefa83bcae59f1daccc0a4
|
|
BLAKE2b-256 checksum How to use checksums |
ea29a21e35ce10d602e7f9bd58285cc1a286d2cef7f81f89753700eccdff6823
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/10.1.0 pkginfo/1.13.3 requests/2.34.2 requests-toolbelt/1.0.0 tqdm/4.70.1 CPython/3.14.8
|
Release files / json_schema_parser-1.0.2-py3-none-any.whl
| Download URL | json_schema_parser-1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9bed9d30554a5893081f4e439c5858cc538580173136d3e30b4417ac40a54ba
|
|
BLAKE2b-256 checksum How to use checksums |
8b224202c076c47b756ee506b53f46f4fa42724d4b150111364add0f01f0a0fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/10.1.0 pkginfo/1.13.3 requests/2.34.2 requests-toolbelt/1.0.0 tqdm/4.70.1 CPython/3.14.8
|
Security for json-schema-parser 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.