JSON to TypeScript Interfaces
Paste sample JSON and get TypeScript interfaces: nested objects, arrays, optional fields and unions.
Also called: JSON to TS, TypeScript interface generator.
JSON to TypeScript Interfaces
Paste sample JSON and get TypeScript interfaces: nested objects, arrays, optional fields and unions.
Watch: how to use the JSON to TypeScript Interfaces (12 seconds)
Recorded on a phone, steps written on screen, no sound.
About the JSON to TypeScript Interfaces
Paste sample JSON and get TypeScript interfaces, including nested objects, arrays, optional fields and union types. Choose the root type name and whether to add “export”.
How to use the JSON to TypeScript Interfaces
- Add your inputFill in sample JSON and root type name. An example is already filled in, so you can press Run tool first to see how it works.
- Pick the optionsadd "export" (the defaults suit most uses).
- Press Run toolThe result appears right under the button.
- Copy or download the resultCopy text results with Copy output; when the tool makes a picture or file, use its Download button.
This tool works inside your browser: what you enter stays on your device.
Example
A sample input and the result the JSON to TypeScript Interfaces gives for it (produced by the tool itself, not typed by hand).
- Sample JSON
- {"id":1,"name":"Sara","tags":["a","b"],"address":{"city":"Lahore","zip":null}}
- Root type name
- Root
Result:
interface Root {
id: number;
name: string;
tags: string[];
address: Address;
}
interface Address {
city: string;
zip: null;
}Good to know
- What you need
- You type or choose: Sample JSON, Root type name
- Where it runs
- In your browser, on your device.
- Cost
- Free, no sign-up.
Questions
How are optional fields found?
A key missing from some array items becomes optional.
Are dates typed as Date?
No, JSON dates are strings.