JSON to TypeScript Converter
Generate TypeScript interfaces from a JSON sample, with optional and nullable fields worked out for you
JSON Input
TypeScript Output
What does the JSON to TypeScript converter generate?
Typing an API response by hand is easy to get slightly wrong, and slightly wrong types are worse than none. Paste a JSON sample here and you get one export interface per object, root first, using the object types you'd write yourself: string, number, boolean, arrays as Device[], nested objects as their own interfaces.
The useful part is that every element of an array is looked at, not just the first. Keys that only some items have become optional (coupon?: string), values that are sometimes null become Customer | null, and arrays with mixed contents become unknown[] instead of a confident wrong type. Keys that aren't valid identifiers, like first name or user-id, are quoted. If two different objects share a key name, the second interface is named after its parent (BillingAddress) so the two don't merge through declaration merging.
An empty object becomes Record<string, unknown>, and a root array also gets a type alias, export type RootObjectList = RootObject[];. Integers past Number.MAX_SAFE_INTEGER are still typed number, but a comment warns you that JSON.parse rounds them. The output is checked with tsc --strict. There are no Zod schemas or runtime type guards here, only types; they disappear at compile time and don't validate anything. It all runs in your browser.
How to use it
The interfaces update as you type.
Paste JSON or upload a file
Paste into the JSON Input panel, Upload a .json or .txt file, or click Sample. Example input:
{"subscriberId": "SUB-1001", "plan": "Unlimited 5G", "dataUsage": 45.2, "status": "active"}Paste several records as an array if you have them; the more real examples, the better the optional and nullable fields come out. Use the JSON Validator if the input won't parse.
Read the interfaces
The TypeScript Output panel lists the root interface first and the nested ones after it.
Copy or download
Copy the code or Download interfaces.ts, then import the types where you fetch the data: const order: RootObject = await res.json();.
Where this saves time
Typing fetch() responses
Paste the JSON your endpoint returns and annotate await res.json() with the generated type, so order.customer.email autocompletes and typos fail the build.
Front-end and back-end contracts
Generate interfaces from a real response and share them between a React or Angular front end and a Node back end while the API settles down.
Third-party webhooks
Paste a handful of webhook payloads as an array. Fields that only appear in some events come out optional, which is exactly what your handler needs to know.
Config files
Type a JSON config once and get errors in your editor when someone mistypes a key in code that reads it.
Common Questions
Does it generate Zod schemas or type guards?
No. It generates TypeScript interfaces only, which are erased at compile time and don't check data at runtime. If you need validation, write a schema with a library like Zod and use the interfaces as a guide.
Why is a field optional when my sample has it?
Because at least one other object in the same array didn't have that key. The tool merges all array items, so ? means "absent in some records", and | null means "null in some records".
What about very large numbers?
TypeScript has no 64-bit integer type for JSON. IDs past 2^53 are typed number with a comment, because JSON.parse will round them. If you need every digit, have the API send them as strings, or parse with a reviver and type them as string or bigint.
Why unknown and not any?
unknown forces you to check a value before using it, which is the right default for data whose type the sample couldn't pin down. Change it to any if you prefer.
What if the root is an array?
The objects inside become RootObject, and you also get export type RootObjectList = RootObject[];. A root that is null, a string or an array of plain values gives a short message instead of code.
Is my JSON uploaded?
No. The interfaces are generated by JavaScript in your browser and nothing is sent to a server. Input is capped at 256 KB.
Other JSON Tools You Might Need
Need the same payload in another language, or want to validate it first?