npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts2json-schema

v1.4.0

Published

Build JSON schemas for your typescript types matching a pattern.

Readme

Typescript to JSON Schema Generator

Simple utility that helps you generate schemas for typescript types. You can use this utility to build schema from all files in a directory and also provide options to limit to a fixed pattern of types.

Why use this?

This utility allows you to create schemas using either typescript-json-schema or ts-json-schema-generator. It enhances the functionality of ts-json-schema-generator by allowing you to create individual schema files for specific types. Additionaly the utility also supports pattern matching for filenames and typenames that give you a lot of control in generating schemas within your workflow.

Installation

Global: npm install -g ts2json-schema Local: npm install ts2json-schema

Usage

The utility only supports CLI usage.

Command line

Usage: ts2json-schema -p <source/directory/of/types> -m <pattern to match against types>

Options:
  --path, -p            Path to source directory where you have types.               [string]
  --match, -m           Regex pattern to filter types.                               [string]
  --out, -o             Path where you want utility to create schema files.          [string]  [default: "<source path>/../schema"]
  --verbose, -v         Enable verbose output for logging.                           [boolean] [default: false]
  --debug, -D           Enable debug output.                                         [boolean] [default: false]
  --filematch, -f       Regex pattern to filter files.                               [string]  [default: ".*"]
  --vega, -A            Use vega/ts-json-schema-generator.                           [boolean] [default: false]
  --tsconfig, -t        Provide path to tsconfig including filename.                 [string]
  --root, -R            Root path to source files.                                   [string]
  --exclude, -e         Exclude types matching pattern                               [string]

More on pattern matching

Pattern matching allows you to isolate and filter types that need validation. This can reduce the schema generation time and make it easier to build schema for only unknown data that needs validation. You can use regex rules to create the pattern. For e.g. if I want to create schemas for all types in the source files that end with Config then I can add the option -m .+Config$.

Using within typescript workflow

  • Install as development dependency in your project npm -D install ts2json-schema

  • Add generateSchema command to your package.json

...
"scripts": [
	"generateSchema": "ts2json-schema -v -p <path to directory of models> -m <pattern to match>",
	"build": "generateSchema && tsc" 
]
...
  • Execute npm run generateSchema to generate schemas as you are working through your project.

Demo

  • Install locally npm install ts2json-schema

  • Execute npm run demo

  • Check ./models for input examples and ./schema for output schemas.

Limitations

  • This utility uses typescript-json-schema or vega/ts-json-schema-generator to generate schemas. If using the default generator please follow the type definition in the api-docs to get the best of this. This also means that all the bugs and limitations of typescript-json-schema and vega/ts-json-schema-generator also apply to this project.

  • This utility only read files at the top level in the source directory. If you are interested in recursive behavior then feel free to file a enhancement request and/or add a PR.

Known Limitations with ts-json-schema-generator

This generator requires that the type files are within the same path as the rootDir path in the tsconfig file. You will need to accordingly organize your model/interface/type files. For e.g. if your rootDir is ./src then your type files can be placed in any child or grand-child directory of ./src

Background

Inspired and builds upon typescript-json-schema, vega/ts-json-schema-generator, typescript-json-validator