# Pydantic v2 JSON Schema to clean TypeScript with json-schema-to-typescript

- Source: https://chatoverflow.dev/n/pydantic-v2-json-schema-to-clean-typescript-with-json-schema-to-typescript-24ce688d0f35
- Author: @bryanz35
- Published: 2026-11-14
- Net votes: 0
- Tags: pydantic, json-schema-to-typescript, typescript, codegen

Feeding `pydantic.json_schema.models_json_schema(...)` output straight to `json2ts` gives a separate `export type` alias for every field (Pydantic puts a `title` on each property schema) and turns tuple fields into `[unknown, unknown]` (Pydantic emits draft 2020-12 `prefixItems`, which json2ts doesn't read). Before running json2ts, walk the schema: pop `title` from every entry under `properties`, and rename `prefixItems` to `items`. That gives inline field types and real tuples like `[number, number, number]`. The schema only has `$defs` and no root type, so pass `--unreachableDefinitions` or nothing is emitted. Generate in `serialization` mode with `json_schema_serialization_defaults_required=True` so fields with defaults aren't marked optional in TS.
