Skip to main content

jsonschema-ts

Python to TypeScript converter, powered by json-schema-to-typescript

Convert JSON Schema (from Pydantic v2 or any source) into clean TypeScript interfaces. A thin Python wrapper around the battle-tested json-schema-to-typescript engine.

from jsonschema_ts import convert

schema = {
    "type": "object",
    "properties": {
        "id": {"type": "integer"},
        "name": {"type": "string"},
        "email": {"type": "string", "format": "email"},
    },
    "required": ["id", "name", "email"],
}

ts = convert(schema, "User")
# export interface User {
#   id: number;
#   name: string;
#   email: string;
# }

Features

  • Zero Python dependencies — pure Python stdlib
  • Battle-tested engine — wraps json-schema-to-typescript
  • Full JSON Schema support — $ref, $defs, allOf, anyOf, oneOf, enums, tuples, circular refs, additional properties, const, and more
  • Pydantic v2 compatible — works directly with model_json_schema() output
  • Batch conversion — single npx call for all $defs
  • Clean output — Prettier-formatted, export interface declarations

Requirements

  • Python ≥ 3.11
  • Node.js ≥ 18 (with npx) — for the TypeScript generation engine

Installation

pip install jsonschema-ts

The first call to convert() will prompt npx to cache json-schema-to-typescript.

Usage

from jsonschema_ts import convert, convert_all, collect_defs, ensure_inline_models

# Single schema
ts = convert(schema, "MyType")

# With $defs (for Pydantic models)
defs = collect_defs(schema)
model_ts = convert_all(defs)

# Inline models from pydantic dataclasses (@model)
schemas = ensure_inline_models(schema1, schema2)
defs = collect_defs(*schemas)
model_ts = convert_all(defs)

# Full Pydantic pipeline
from pydantic import BaseModel

class Address(BaseModel):
    street: str
    city: str
    zip: str

class User(BaseModel):
    name: str
    address: Address

schema = User.model_json_schema()
defs = collect_defs(schema)
models = convert_all(defs)
main = convert(schema, "User")

API

| Function | Description | |---|---|---| | convert(schema, name) | Convert single JSON Schema → TypeScript interface | | convert_all(defs) | Convert all $defs → TypeScript interfaces (batch) | | collect_defs(*schemas) | Extract and merge $defs from schemas | | ensure_inline_models(*schemas) | Promote inline object schemas to $defs entries | | assemble(models, procedures) | Combine model interfaces + procedure types into final TS output | | ensure_npx() | Check Node.js/npx availability |

from jsonschema_ts import collect_defs, convert, convert_all, ensure_inline_models, assemble

# ... promote inline models, then collect and convert ...
schemas = ensure_inline_models(raw_schema)
defs = collect_defs(*schemas)
models = convert_all(defs)

# Combine everything into final output
output = assemble(
    models=models,
    procedures="export interface Types { greet(name: string): Promise<string>; }",
)

Why a wrapper?

json-schema-to-typescript has an 8-stage pipeline (resolver → linker → normalizer → parser → optimizer → generator → formatter) with 18 normalization rules handling hundreds of edge cases. Reimplementing this in Python would take months. This package delegates the heavy lifting and focuses on what Python does best: orchestration, $defs collection, and output assembly.

License

MIT

Metadata

Release files for jsonschema-ts 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonschema-ts 0.3.0
File Size Uploaded Provenance
jsonschema_ts-0.3.0.tar.gz 90.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonschema-ts 0.3.0
File Interpreter ABI Platform
jsonschema_ts-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 101.4 kB

Release files / jsonschema_ts-0.3.0.tar.gz

Download URL jsonschema_ts-0.3.0.tar.gz
Size 90.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f26025f974e1775811d00136165200cc4f615722ae8a9ca7b0c65c37257da753
BLAKE2b-256 checksum
How to use checksums
f07a56d95a607bc6f7fb972194fc5b11692a1883ace66c12fbe13278c198b339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / jsonschema_ts-0.3.0-py3-none-any.whl

Download URL jsonschema_ts-0.3.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f60c52a8f6fb3b8d26f95944bdc61ed8b5a6bb647380db39001f819afb11402f
BLAKE2b-256 checksum
How to use checksums
b460552813a34b9e988b45323862a81d933555757bf08f13eb30ede107ddeb39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for jsonschema-ts 0.3.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page