Tools: # ⚡ Generate TypeScript Types From JSON in Seconds - No Configuration - 2025 Update
The Problem We're Solving
🎯 Meet json-to-ts-generator
Features
Real-World Examples
Example 1: API Response
Example 2: Config File
Example 3: Piping (My Favorite)
Why This is Different
Installation & Quick Start
Global (Recommended)
Local (Dev dependency)
One-Shot (No install)
Common Use Cases
1️⃣ Documenting API Responses
2️⃣ Converting Third-Party Schemas
3️⃣ Working with Mock Data
4️⃣ Microservices Communication
5️⃣ Lambda/Serverless Functions
Advanced: Programmatic API
Performance & Reliability
What Developers Are Saying
Open Source & Contributing
TL;DR: You Need This If... Have you ever received a raw JSON object and spent the next 20 minutes manually writing TypeScript types for it? What if I told you there's a one-liner that does this automatically? Every developer encounters this: With json-to-ts-generator: One command. Zero websites. Done. ✨ npm install -g json-to-ts-generator An intelligent CLI tool that generates TypeScript types from JSON instantly, with zero dependencies and zero configuration. ✨ Smart Type Inference ⚙️ Fully Customizable 📂 Multiple Input Methods Not just a CLI - use it in your code: 🛡️ Robust Error Handling "Finally, a tool that does exactly what I need without overthinking it. No config, no UI, just JSON → types." — Developer, StackOverflow "This saves me hours every week. No more manual type writing." — Open Source Maintainer "The CLI is so intuitive, I showed it to my team and they immediately made it part of our workflow." — Tech Lead github.com/DarnerDiaz/json-to-ts-generator That's it. Welcome to your new favorite developer tool. 🚀 Have you used json-to-ts-generator? What's your use case? Drop a comment below! 👇 Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to ? It will become hidden in your post, but will still be visible via the comment's permalink. as well , this person and/or
// The old way - manual, error-prone interface User { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: // The old way - manual, error-prone interface User { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: // The old way - manual, error-prone interface User { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: json-to-ts '{"id":1,"name":"John","email":"[email protected]","createdAt":"2024-03-22","isVerified":true}' CODE_BLOCK: json-to-ts '{"id":1,"name":"John","email":"[email protected]","createdAt":"2024-03-22","isVerified":true}' CODE_BLOCK: json-to-ts '{"id":1,"name":"John","email":"[email protected]","createdAt":"2024-03-22","isVerified":true}' CODE_BLOCK: interface Root { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: interface Root { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: interface Root { id: number; name: string; email: string; createdAt: string; isVerified: boolean; } CODE_BLOCK: cat api-response.json | json-to-ts -n ApiResponse CODE_BLOCK: cat api-response.json | json-to-ts -n ApiResponse CODE_BLOCK: cat api-response.json | json-to-ts -n ApiResponse COMMAND_BLOCK: # From file json-to-ts package.json # Inline JSON json-to-ts '{"name":"John","age":30}' # From pipe (streaming) cat data.json | json-to-ts -n DataType # Save to file curl api.example.com/users | json-to-ts -n User -o types.ts COMMAND_BLOCK: # From file json-to-ts package.json # Inline JSON json-to-ts '{"name":"John","age":30}' # From pipe (streaming) cat data.json | json-to-ts -n DataType # Save to file curl api.example.com/users | json-to-ts -n User -o types.ts COMMAND_BLOCK: # From file json-to-ts package.json # Inline JSON json-to-ts '{"name":"John","age":30}' # From pipe (streaming) cat data.json | json-to-ts -n DataType # Save to file curl api.example.com/users | json-to-ts -n User -o types.ts CODE_BLOCK: { "status": "success", "data": { "user": { "id": 123, "profile": { "firstName": "John", "lastName": "Doe", "avatar": "https://..." } }, "posts": [ { "id": 1, "title": "First Post", "likes": 42 } ] } } CODE_BLOCK: { "status": "success", "data": { "user": { "id": 123, "profile": { "firstName": "John", "lastName": "Doe", "avatar": "https://..." } }, "posts": [ { "id": 1, "title": "First Post", "likes": 42 } ] } } CODE_BLOCK: { "status": "success", "data": { "user": { "id": 123, "profile": { "firstName": "John", "lastName": "Doe", "avatar": "https://..." } }, "posts": [ { "id": 1, "title": "First Post", "likes": 42 } ] } } CODE_BLOCK: json-to-ts -n ApiResponse data.json CODE_BLOCK: json-to-ts -n ApiResponse data.json CODE_BLOCK: json-to-ts -n ApiResponse data.json CODE_BLOCK: interface ApiResponse { status: string; data: { user: { id: number; profile: { firstName: string; lastName: string; avatar: string; }; }; posts: { id: number; title: string; likes: number; }[]; }; } CODE_BLOCK: interface ApiResponse { status: string; data: { user: { id: number; profile: { firstName: string; lastName: string; avatar: string; }; }; posts: { id: number; title: string; likes: number; }[]; }; } CODE_BLOCK: interface ApiResponse { status: string; data: { user: { id: number; profile: { firstName: string; lastName: string; avatar: string; }; }; posts: { id: number; title: string; likes: number; }[]; }; } CODE_BLOCK: json-to-ts -n Config -r -o config.types.ts config.json CODE_BLOCK: json-to-ts -n Config -r -o config.types.ts config.json CODE_BLOCK: json-to-ts -n Config -r -o config.types.ts config.json CODE_BLOCK: interface Config { readonly api: string; readonly timeout: number; readonly retries: number; } CODE_BLOCK: interface Config { readonly api: string; readonly timeout: number; readonly retries: number; } CODE_BLOCK: interface Config { readonly api: string; readonly timeout: number; readonly retries: number; } COMMAND_BLOCK: curl https://api.github.com/users/torvalds | json-to-ts -n GitHubUser COMMAND_BLOCK: curl https://api.github.com/users/torvalds | json-to-ts -n GitHubUser COMMAND_BLOCK: curl https://api.github.com/users/torvalds | json-to-ts -n GitHubUser COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts --help COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts --help COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts --help COMMAND_BLOCK: npm install --save-dev json-to-ts-generator npx json-to-ts data.json COMMAND_BLOCK: npm install --save-dev json-to-ts-generator npx json-to-ts data.json COMMAND_BLOCK: npm install --save-dev json-to-ts-generator npx json-to-ts data.json CODE_BLOCK: npx json-to-ts-generator data.json CODE_BLOCK: npx json-to-ts-generator data.json CODE_BLOCK: npx json-to-ts-generator data.json COMMAND_BLOCK: # Fetch real API response and auto-type it curl https://api.example.com/v1/users | json-to-ts -n User -o user-types.ts COMMAND_BLOCK: # Fetch real API response and auto-type it curl https://api.example.com/v1/users | json-to-ts -n User -o user-types.ts COMMAND_BLOCK: # Fetch real API response and auto-type it curl https://api.example.com/v1/users | json-to-ts -n User -o user-types.ts COMMAND_BLOCK: # Your CMS sends JSON - instant types json-to-ts cms-export.json -n CmsContent -o types.ts COMMAND_BLOCK: # Your CMS sends JSON - instant types json-to-ts cms-export.json -n CmsContent -o types.ts COMMAND_BLOCK: # Your CMS sends JSON - instant types json-to-ts cms-export.json -n CmsContent -o types.ts COMMAND_BLOCK: # Generate types from Cypress fixtures json-to-ts cypress/fixtures/user.json -n User COMMAND_BLOCK: # Generate types from Cypress fixtures json-to-ts cypress/fixtures/user.json -n User COMMAND_BLOCK: # Generate types from Cypress fixtures json-to-ts cypress/fixtures/user.json -n User COMMAND_BLOCK: # Service A shares schema as JSON # Service B auto-generates types json-to-ts schema-from-service-a.json -n ServiceASchema COMMAND_BLOCK: # Service A shares schema as JSON # Service B auto-generates types json-to-ts schema-from-service-a.json -n ServiceASchema COMMAND_BLOCK: # Service A shares schema as JSON # Service B auto-generates types json-to-ts schema-from-service-a.json -n ServiceASchema COMMAND_BLOCK: # Event schema → instant types json-to-ts aws-event-schema.json -n LambdaEvent -o handlers/types.ts COMMAND_BLOCK: # Event schema → instant types json-to-ts aws-event-schema.json -n LambdaEvent -o handlers/types.ts COMMAND_BLOCK: # Event schema → instant types json-to-ts aws-event-schema.json -n LambdaEvent -o handlers/types.ts CODE_BLOCK: import { stringToTypeScript, fileToTypeScript } from 'json-to-ts-generator'; // From JSON string const userType = stringToTypeScript( '{"id":1,"name":"John"}', { name: 'User', readonly: true } ); console.log(userType); // Output: interface User { readonly id: number; readonly name: string; } // From file const apiType = await fileToTypeScript('api-response.json', { name: 'ApiResponse' }); CODE_BLOCK: import { stringToTypeScript, fileToTypeScript } from 'json-to-ts-generator'; // From JSON string const userType = stringToTypeScript( '{"id":1,"name":"John"}', { name: 'User', readonly: true } ); console.log(userType); // Output: interface User { readonly id: number; readonly name: string; } // From file const apiType = await fileToTypeScript('api-response.json', { name: 'ApiResponse' }); CODE_BLOCK: import { stringToTypeScript, fileToTypeScript } from 'json-to-ts-generator'; // From JSON string const userType = stringToTypeScript( '{"id":1,"name":"John"}', { name: 'User', readonly: true } ); console.log(userType); // Output: interface User { readonly id: number; readonly name: string; } // From file const apiType = await fileToTypeScript('api-response.json', { name: 'ApiResponse' }); COMMAND_BLOCK: $ json-to-ts invalid.json Error: Invalid JSON Input: invalid.json SyntaxError: Unexpected token } in JSON at position 42 COMMAND_BLOCK: $ json-to-ts invalid.json Error: Invalid JSON Input: invalid.json SyntaxError: Unexpected token } in JSON at position 42 COMMAND_BLOCK: $ json-to-ts invalid.json Error: Invalid JSON Input: invalid.json SyntaxError: Unexpected token } in JSON at position 42 COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts data.json COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts data.json COMMAND_BLOCK: npm install -g json-to-ts-generator json-to-ts data.json - ❌ API response with no types - ❌ Third-party JSON schema - ❌ Mock data for tests - ❌ Database query results - ❌ Config files that need types
- Copy JSON 📋
- Open a type generator website ⌨️
- Paste JSON 🖱️
- Copy generated types 🔄
- Paste into your editor ✅
- Automatically detects primitives, arrays, nested objects
- Handles null values gracefully
- No manual type hints needed - -n
- Custom interface name - -t
- Use type keyword instead of interface - -r
- Mark properties as readonly - -o
- Save to file directly
- Zero external dependencies
- Type-safe everywhere
- Works with complex nested structures
- Build scripts that auto-generate types
- Documentation generators
- Schema validators
- Testing frameworks
- JSON parsing: <1ms
- Type generation: <5ms
- Total time: Usually under 50ms
- Fast installation
- Minimal footprint - 📄 MIT License - 🔧 Contributions welcome - 🐛 Report bugs/feature requests - ⭐ Star if you find it useful! - ✅ You work with APIs/JSON regularly - ✅ You hate manually writing types - ✅ You want a zero-config solution - ✅ You need offline type generation - ✅ You love CLI tools - ✅ You want to save hours shipping faster