JSON → TypeScript
Generate TypeScript interfaces from JSON — optional properties, union types, readonly fields, and nested objects. Paste JSON, get ready-to-use .d.ts definitions.
About this tool
Hand-writing TypeScript interfaces for an API response you just received is busywork — you eyeball the shape, guess which fields are nullable, and hope the next request doesn't add a key. Paste the JSON here and the tool derives the interfaces for you, recursing into nested objects and arrays.
Example: {"id":1,"name":"Alice","address":{"city":"NYC"}} produces two interfaces — RootObject with fields id: number, name: string, address: Address — and a companion Address interface. You can rename the root, mark null values as optional, and toggle the export keyword before copying or downloading the result.
The types are a starting point: if a field is sometimes a string and sometimes a number, the tool emits any rather than guessing a union — refine it once you know the real contract.
FAQ
Why do some fields show as "any"? ›
When a key has mixed types across the sample (e.g. a string in one object and a number in another), or when an array holds different shapes, the tool falls back to any rather than inventing a union. Provide a richer JSON sample or tighten the type by hand once you know the contract.
How are nested objects named? ›
A nested object under a key named "address" becomes an interface called "Address". The field on the parent is then typed as that interface. The root interface name is configurable in the options above.
Does it handle arrays of objects? ›
Yes. If the root is an array of objects, the first element defines the element interface and the root type becomes that interface followed by square brackets. Empty arrays fall back to any[] since the element type is unknown.
What does "Optional nullable fields" do? ›
When enabled, any field whose value is null in the sample is marked with a question mark (e.g. email?: string), reflecting that the field may be absent. Disable it if null is a valid value you want represented explicitly.
What does "Readonly fields" do? ›
When enabled, every generated property is prefixed with the readonly modifier (e.g. readonly name: string). This is useful when generating types for API responses or immutable data structures where fields should not be reassigned after construction.
How do I share a JSON snippet? ›
Click the Share button to copy a deeplink URL with your JSON encoded in the hash. Anyone opening that link will see the same JSON and generated types automatically. Note that URLs are limited to about 3,000 characters of JSON.