Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

snaptype

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snaptype

Generate TypeScript types and Zod schemas from JSON, CSV, or live API responses

latest
npmnpm
Version
1.0.2
Version published
Weekly downloads
10
400%
Maintainers
1
Weekly downloads
 
Created
Source

snaptype

Stop writing TypeScript types by hand.

snaptype is a CLI that turns your JSON files, CSV exports, REST APIs, and OpenAPI/GraphQL schemas into TypeScript interfaces and Zod schemas — in one command.

snaptype.dev — docs, Pro licence, live demo

The problem

Every time you hit an API or open a data file, you end up writing types by hand. You copy-paste a JSON response, squint at the shape, type out an interface. The API changes — you do it again.

snaptype automates that step entirely.

Quick start

npx snaptype from-json ./user.json -o types.ts

Input — user.json:

{
  "id": 1,
  "name": "Alice",
  "email": "alice@example.com",
  "role": "admin",
  "createdAt": "2024-01-15T10:30:00Z",
  "address": { "city": "Paris", "zip": "75001" }
}

Output — types.ts:

// Generated by snaptype — do not edit manually

export interface Address {
  city: string;
  zip: string;
}

export interface User {
  id: number;
  name: string;
  email: string; // email
  role: string;
  createdAt: string; // ISO 8601
  address: Address;
}

Add --zod to also get a ready-to-use Zod schema:

npx snaptype from-json ./user.json -o types.ts --zod
// types.zod.ts — Generated by snaptype

import { z } from 'zod';

export const AddressSchema = z.object({
  city: z.string(),
  zip: z.string(),
});

export const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string().email(),
  role: z.string(),
  createdAt: z.string().datetime(),
  address: AddressSchema,
});

export type User = z.infer<typeof UserSchema>;

Installation

npm install -D snaptype
# peer dep if you use --zod
npm install zod

Requires Node.js 20+.

Input sources

SourceCommand
Local JSON filesnaptype from-json ./data.json -o types.ts
Live API / URLsnaptype from-url https://api.example.com/users -o types.ts
CSV filesnaptype from-csv ./export.csv -o types.ts
stdin (pipe)curl https://… | snaptype from-stdin --name User -o types.ts
OpenAPI 3.x specsnaptype from-openapi ./openapi.yaml -o types.ts
GraphQL endpointsnaptype from-graphql https://…/graphql -o types.ts (Pro)

What it infers automatically

  • Primitives: string, number, boolean, null
  • Nested objects and arrays
  • Optional and nullable fields
  • Semantic hints on string fields — email, url, ISO 8601 dates → .email(), .url(), .datetime() in Zod
  • Enum / union literals when a field has low cardinality (≤ 10 distinct values, ≥ 80% coverage)
  • $ref, oneOf, allOf, anyOf from OpenAPI specs
  • GraphQL scalars, enums, unions, and interfaces

More commands

# Detect breaking changes between two type files (Pro)
snaptype diff old.ts new.ts

# Generate realistic mock data from a schema (Pro)
snaptype mock ./types.ts -o mocks.ts

# Convert existing TypeScript interfaces to Zod schemas (Pro)
snaptype to-zod ./src/types/user.ts

# Re-export all generated files in one barrel file
snaptype barrel ./src/types

# Watch a source file and regenerate on change (Pro)
snaptype from-json ./api.json -o types.ts --watch

Project config

Drop a .snaptyperc at the root of your project to stop repeating flags:

{
  "naming": "camel",
  "emit": "interface",
  "zod": true,
  "outDir": "src/types"
}

CLI flags always take priority. See the configuration docs for all keys.

Free vs Pro

Pro is a one-time purchase — no subscription, works across machines.

FeatureFreePro
from-json (single file)
from-url, from-csv, from-stdin
from-openapi (single file)
TypeScript + Zod generation
Semantic inference (email, date, url)
Enum / union literal detection
--readonly, .snaptyperc, barrel
from-json / from-url (multiple files)
from-graphql
snaptype diff + --ci
snaptype mock
snaptype to-zod
--watch

Get Pro at snaptype.dev

License

MIT — free tier is free forever. Pro features require a licence key.

Keywords

typescript

FAQs

Package last updated on 05 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts