json2ts for Mac
json-schema-to-typescript [![npm]]( [![mi…
json2ts — overview
json-schema-to-typescript (https://github.com/bcherny/json-schema-to-typescript/actions?query=branch%3Amaster+workflow%3ACI) [![npm]](https://www.npmjs.com/package/json-schema-to-typescript) [![mit]](https://opensource.org/licenses/MIT) ![node]
Compile JSON Schema to TypeScript typings.
Example
Check out the live demo.
Input:
Output:
Installation
Requires Node.js 22.19 or later. (json-schema-to-typescript 16.x is the last release line that runs on Node.js 16–20.)
Usage
json-schema-to-typescript is easy to use via the CLI, or programmatically.
CLI
First make the CLI available using one of the following options:
Then, use the CLI to convert JSON files to TypeScript typings:
You can pass any of the options described below (including style options) as CLI flags. Boolean values can be set to false using the no- prefix.
The CLI automatically loads the closest Prettier configuration for the generated output file (when writing to stdout: for a .d.ts next to the input file, or in the working directory for piped input). Explicit --style.* flags take precedence over discovered settings, and the output is always parsed as TypeScript whatever parser the config names. A Prettier config that cannot be loaded (invalid syntax, a missing plugin) now fails the run. This does not affect the programmatic API.
Compiling a directory of schemas that reference each other (experimental)
By default each input file is compiled on its own, so a type that several files reach through a $ref is declared again in every output file. With --imports, a directory or glob is compiled together: a type that lives in another file of the set becomes an import type from that file's module instead of a copy.
For example, with common.json holding shared definitions, and a.json and b.json using them and each other:
(Without --imports, a.d.ts and b.d.ts each declare their own Thing, Tag, A and B, plus a second A1/B1 where the cycle comes back around, and common.d.ts declares only Common.)
Details
将 JSONSchema 编译为 TypeScript 类型声明
How to install json2ts
- Open Terminal (press ⌘ + Space and type “Terminal”).
- If Homebrew is not installed yet, run the command below first.
- Run this command:
Latest 10 releases
This project has no GitHub releases yet.
Prebuilt bottle platforms
Official Homebrew bottles cover:
- all
⚠️ No prebuilt bottle for Intel Macs; Intel users need brew install --build-from-source to build from source.
Compared with similar apps
Only public metadata is compared, with no subjective recommendation; see the compare pages for field-by-field comparisons.
| App | Version | License | Architecture | 30-day installs |
|---|---|---|---|---|
| json2ts | 16.0.0 | MIT | CLI | 0 |
| dhall-bash | 1.42.2 | BSD-3-Clause | CLI | 1 |
| dtsroll | v1.8.2 | MIT | CLI | 1 |
| cotila | v1.1.1 | Apache-2.0 | CLI | 0 |
Similar apps: Command-line Tools
dhall-bash
You will probably want to read the language-agnostic README here:dtsroll
Are you publishing a TypeScript project where consumers encounter type-checking errors like:cotila
Cotila (compile-time linear algebra) is a header-only library that provides a set of linear…ctre
Compile-time regular expression matcher for C++openssl@4
Cryptography and SSL/TLS Toolkitxz
General-purpose data compression with high compression ratioCategories: Command-line Tools