Skip to main content

Convert jsonschema to pydantic model

Project description

jsonschema2pydantic

Convert jsonschema to pydantic model

Installation

pip install jsonschema2pydantic

Examples

from pydantic import BaseModel
from jsonschema2pydantic import generate_schema

class Model(BaseModel):
    field_1: str
    field_2: int
    field_3: bool

DynamicModel = generate_schema({
  "properties": {
    "field_1": {
      "title": "Field 1",
      "type": "string"
    },
    "field_2": {
      "title": "Field 2",
      "type": "integer"
    },
    "field_3": {
      "title": "Field 3",
      "type": "boolean"
    }
  },
  "required": [
    "field_1",
    "field_2",
    "field_3"
  ],
  "title": "Model",
  "type": "object"
})

assert Model.model_json_schema() == DynamicModel.model_json_schema()

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

jsonschema2pydantic-0.1.3.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

jsonschema2pydantic-0.1.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema2pydantic-0.1.3.tar.gz.

File metadata

  • Download URL: jsonschema2pydantic-0.1.3.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for jsonschema2pydantic-0.1.3.tar.gz
Algorithm Hash digest
SHA256 99729f8b6dbf907cb133baec2f91690d6fa8b472b82a36354245b4c5579ef634
MD5 13a789924db541e7b3ae85272a18471e
BLAKE2b-256 600653b8f5cdc0f397c61b25c5adb0cd993f1db7f1738f9ce9288081bd1e5a0f

See more details on using hashes here.

File details

Details for the file jsonschema2pydantic-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema2pydantic-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eaadcca2d9ed628f4a93dade64f9bcab0efb5b125031a7ebca87d9ba5ce488e7
MD5 df7fc8eba6ff44d40d1d517f13e6464e
BLAKE2b-256 7a980824a4359949c69817f132269739055bf770f48196a35ede195f8525e786

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