JSON to TypeScript Converter
Updated Free mock REST & WebSocket APIs
Paste a sample JSON response and get TypeScript interfaces you can drop into your code. Nested objects get their own named interfaces, fields missing from some array items become optional, and mixed values become unions.
🔒 Runs in your browser — nothing you paste is uploaded.
How to generate TypeScript types from JSON
- Paste a representative JSON sample — ideally an array with several items so optional fields can be detected.
- Name the root type and choose interface or type, export, readonly or inline nested types.
- Copy the code or download types.ts, then refine names and narrow string fields to literal unions where you know the values.
How types are inferred
| Sample JSON | TypeScript |
|---|---|
"id": 1 | id: number; |
"tags": ["a", "b"] | tags: string[]; |
"items": [] | items: unknown[]; — add one item to the sample for a real type |
"bio": null | bio: unknown | null; |
[{"a": 1}, {"a": "x", "b": true}] | a: number | string; b?: boolean; |
"is-verified": true | "is-verified": boolean; (quoted key) |
Objects in a field called orders become an Order interface (singularized), objects with an identical structure share one interface, and names are PascalCased and kept unique.
Types from a sample are a starting point
A sample only shows what happened to be in it. Before committing the types, check: fields that can be missing (mark them ?), strings with a fixed set of values (status: "paid" | "refunded"), and ISO dates you may want to parse. If the data comes from an API at runtime, validate it — TypeScript types disappear at compile time. Our JSON to Zod generator gives you a runtime validator and the type in one go.
Related tools
Frequently asked questions
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser with JavaScript, so your JSON never leaves your device and isn't logged or stored.
Interface or type — which should I pick?
For object shapes they're interchangeable. Interfaces can be extended and merged and give slightly clearer error messages; type aliases can also express unions. Many codebases simply pick one style.
How are optional properties detected?
When objects at the same position (for example the items of an array) don't all have a key, that key is marked optional with ?.
Does it validate data at runtime?
No — TypeScript types are compile-time only. Use the JSON to Zod generator to get a schema that validates data when your app runs.
Your business here? Sponsor this tool from $16/week. See placements