☰ Menu
CLI Open source

json2ts for Mac

json2ts

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

  1. Open Terminal (press ⌘ + Space and type “Terminal”).
  2. If Homebrew is not installed yet, run the command below first.
  3. 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.

Compared with similar apps
AppVersionLicenseArchitecture30-day installs
json2ts16.0.0MITCLI0
dhall-bash1.42.2BSD-3-ClauseCLI1
dtsrollv1.8.2MITCLI1
cotilav1.1.1Apache-2.0CLI0

Similar apps: Command-line Tools

Leave a comment

评论表单加载中…