finds.dev← search

// the find

bcherny/json-schema-to-typescript

★ 3,347 · TypeScript · MIT · updated Sep 2026

Compile JSON Schema to TypeScript type declarations

Compiles JSON Schema into TypeScript type declarations, through either the `json2ts` CLI or the `compile` and `compileFromFile` API. It suits teams generating types from schemas they don't control, such as vendor API specs or config formats, as a build step.

- The draft-support table marks every keyword as supported, ignored, or not expressible, and says each row was checked by compiling a one-keyword schema through the CLI. You can see what the output will and won't reflect before you run it.

- `format: false` skips Prettier. The README's benchmark shows the 60-schema Azure template dropping from 8.3 s and 958 MB to 3.7 s and 415 MB, so build-step users get a measured knob.

- `$ref`s to loopback, private-network, and internal HTTP hosts are refused by default. That matters when schemas come from untrusted input, and most generators don't guard it.

- `tsEnumNames` is validated. Duplicate or missing names throw a `ValidationError`, and names TypeScript would read as numbers get an underscore prefix instead of producing broken output.

- Constraint keywords like `minimum`, `pattern`, `multipleOf`, and `uniqueItems` have no TypeScript equivalent and leave no trace in the output. The generated types promise less than the schema says, so runtime validation is still needed at the boundary.

- Newer drafts are thin. `if`/`then`/`else` contributes nothing, `prefixItems` becomes `unknown[]`, `$anchor` errors, and `unevaluatedProperties` is only partial. Anyone writing 2020-12 schemas has to check the output by hand.

- Internally it models draft 4 (`JSONSchema4`) and layers later drafts on top. Edge cases stack up: a `$ref` to a boolean schema crashes (#809), and a root `true` or `false` errors out.

- The `--imports` cross-file mode is marked experimental and only covers `definitions`, `$defs`, and root types. Schemas under `components/schemas` in OpenAPI documents can't be imported yet, which will hit teams working from OpenAPI.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →