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

@darth_sith_99/json-to-interface

v2.1.0

Published

Generate TypeScript API contracts from success and error JSON payloads.

Downloads

240

Readme

📦 json-to-interface

@darth_sith_99/json-to-interface is a simple CLI tool that lets you generate TypeScript interfaces directly from a JSON payload. It’s perfect for quickly scaffolding data contracts for your frontend or backend project.

✨ Features

  • 🧠 Infers types from JSON structure
  • 📁 Outputs .ts files with clean, readable interfaces
  • 🏃‍♂️ No install required — run instantly with npx
  • 🤖 Interactive prompts, or non-interactive arguments for scripts and coding agents

🚀 Getting Started

✅ Requirements

  • Node.js v18.13 or higher
  • Internet access (for npx to fetch the package)

🛠️ Usage

Prepare two JSON mock files in the same folder: one for the success response and one for the error response.

sample/
├── success.json
└── error.json

Interactive mode

Run the CLI with no arguments and answer the prompts:

npx @darth_sith_99/json-to-interface
  1. Select the API method.
  2. Enter the API name, for example currentFlight.
  3. Enter the folder containing the mocks, for example ./sample/.
  4. Confirm the success and error mock filenames.

The generated file is saved in the same folder, for example sample/GetCurrentFlight.contract.ts.

Argument mode

Pass arguments to skip the prompts. Use this from scripts, CI, or coding agents that cannot answer interactive questions.

npx @darth_sith_99/json-to-interface \
  --method GET \
  --name currentFlight \
  --directory ./sample/ \
  --success success.json \
  --error error.json \
  --suffix-interface Response \
  --suffix-file types

This writes sample/GetCurrentFlight.types.ts with names such as GetCurrentFlightSuccessDataResponse.

| Option | Short | Required | Description | Default | | --- | --- | --- | --- | --- | | --method | -m | Yes | API method: GET, POST, PUT, PATCH, or DELETE | | | --name | -n | Yes | API name used in type names and the filename | | | --directory | -d | Yes | Folder with the mocks, also used for output. Must look like ./sample/ | | | --success | -s | No | Success mock filename | success.json | | --error | -e | No | Error mock filename | error.json | | --suffix-interface | -i | No | Suffix added to every generated type name | APIResponseType | | --suffix-file | -f | No | Suffix in the output filename | contract | | --help | -h | No | Show usage | |

--suffix-interface and --suffix-file only exist in argument mode. Interactive mode always uses the values from .jsonrc or the defaults.


⚙️ Configuration

Defaults can be changed with a .jsonrc file in the directory where you run the CLI:

SUCCESS_MOCK_FILE=success.json
ERROR_MOCK_FILE=error.json
SUFFIX_INTERFACE=APIResponseType
SUFFIX_FILE=contract

| Key | Controls | Default | | --- | --- | --- | | SUCCESS_MOCK_FILE | Default success mock filename | success.json | | ERROR_MOCK_FILE | Default error mock filename | error.json | | SUFFIX_INTERFACE | Suffix added to every generated type name | APIResponseType | | SUFFIX_FILE | Suffix in the output filename | contract |

Values are resolved in this order: CLI argument, then .jsonrc, then the built-in default.


📄 Output

For --method GET --name currentFlight with the default suffixes, the CLI generates GetCurrentFlight.contract.ts:

export interface GetCurrentFlightSuccessRootAPIResponseType {
  meta?: GetCurrentFlightSuccessMetaAPIResponseType;
  data?: GetCurrentFlightSuccessDataAPIResponseType;
}

export interface GetCurrentFlightErrorRootAPIResponseType {
  meta?: GetCurrentFlightErrorMetaAPIResponseType;
  error?: GetCurrentFlightErrorErrorAPIResponseType;
}

export type GetCurrentFlightRootAPIResponseType =
  | GetCurrentFlightSuccessRootAPIResponseType
  | GetCurrentFlightErrorRootAPIResponseType;

If the output file already exists, it is replaced.


📦 Publish to npm

This package is published to the public npm registry as @darth_sith_99/json-to-interface. Publishing is done from your machine with your npm account. The @darth_sith_99 scope must belong to that account.

npm login
pnpm publish

pnpm publish builds the package first. npm rejects a version that was already published, so bump version in package.json before the next release.

Install or run it with:

pnpm add @darth_sith_99/json-to-interface

# Or run it without adding it to the project
pnpm dlx @darth_sith_99/json-to-interface --help