JSON to TypeScript
Turn a sample API response or config into TypeScript types you can paste into your project. Nested objects get their own named types.
Types are guessed from this one sample. Paste a list with several records to catch optional keys, and check fields that are null here but hold another type in real data.
How to convert JSON to TypeScript
- Paste JSON or open a .json file.
- Set the root name and choose interface or type.
- Copy the types or save them as types.ts.
Features
- Interfaces or type aliases
- Named types for nested objects
- Optional keys from merged arrays
- Union types and null handling
- export and readonly options
- Optional Zod schema output
Frequently asked questions
How are arrays of different objects handled?
Every object in a list is merged into one type. A key that appears in only some of the objects is marked optional with ?, and a key with different value types becomes a union such as string | number.
What happens to null values?
By default a null field is typed as its other types plus null, for example string | null. Choose “x?: T | null” to also make such fields optional. A field that is only ever null is typed as null.
What is the Zod schema for?
Zod checks data at runtime, for example an API response, and throws if it does not match. Tick “Also make a Zod schema” to get z.object() schemas that match the types.
Why is an empty array typed as unknown[]?
An empty list gives no clue about what it holds. Add one sample item to the JSON, or edit unknown[] to the right type after copying.
Is my data sent to a server?
No. Everything runs in your browser, so configs, API responses and code never leave your device.
Related tools
All Developer Tools →- JSON Formatter Pretty-print messy JSON, find syntax errors fast, or minify it for production.
- Mock Data Generator Create sample data for testing apps, demos and databases, with names and places that look right for Indian users.
- JSONPath Tester Write and debug JSONPath queries used in API tests, Postman, Kubernetes and data pipelines.
- IP Subnet Calculator Type an IP address with a prefix such as 192.168.10.37/24 to see its network details, a binary view and how to split it into smaller subnets.
- HTML, CSS & JS Playground Try out an idea, teach a concept or debug a snippet without setting up a project.
- String Escape / Unescape Make text safe to paste inside a string literal, query or file format, or turn escaped text from a log back into something readable.