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.2.tar.gz (31.3 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.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonschema2pydantic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d1b2657c54e1460c51a918d5cbf47442fda9213acb0f78140fed72ade75d8542
MD5 c943e37f063e2e56ec34dd7317c00fda
BLAKE2b-256 2243a06db1b2b6aa27625696324518b1290e7cfab38975a80fbac5ecd677f2e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema2pydantic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a376cda3752c4d533173b7a19afb6cdf42f9c435832c9ece96582b5f8fd70cc
MD5 d0dc07f6c823212d915d3e149ae2e83d
BLAKE2b-256 f304bec3efa5c67f3790270f057806dfabfd6e9e7c13777d62b52c3160687716

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