JSON to TypeScript
Paste a sample JSON response and get TypeScript interfaces for it - with nested types named for you and optional fields marked.
- 1Select
- 2Configure
- 3Process
- 4Download
Your JSON is processed in your browser and never uploaded.
Accepts JSON, YAML, CSV, XMLPaste text or open a file up to 20 MBResult
Everything happens in your browser - your data is never sent anywhere.
How the types are worked out
Every object in the sample becomes an interface, named after the key it sits under: an address field gets an Address interface, and an array called items gets an Item interface for its elements. Numbers, strings and booleans map to number, string and boolean.
When an array holds several objects, their fields are merged. A field that's missing in some of them is marked optional with ?, and a field that's null in some of them becomes a union such as string | null. Keys that aren't valid identifiers, like first-name, are kept in quotes so they still match the JSON exactly.
Getting accurate types from a sample
Generated types can only describe the data they're given. A better sample gives better types.
- Include variety. Use a response with several items, including ones where optional fields are missing or null.
- Watch for empty arrays. An empty array has no items to learn from, so its element type is unknown until you add an example item.
- Mixed types become unknown. If a field is sometimes a number and sometimes a string, its type is unknown - a sign the API needs a closer look.
- Check the names. Type names come from keys. Rename them in your editor if the API uses generic keys like data or result.
Other languages and schemas
The same sample can become Python TypedDicts, Go structs with json tags, C# classes with JsonPropertyName attributes or Java records with Jackson annotations - choose the language above the result. Keys are mapped to each language's naming style while the original JSON names are kept in the tags and attributes.
If you'd rather validate data at runtime, the Schema tab generates a JSON Schema (draft 2020-12) from the same sample, with required fields and nullable types.
How to convert JSON to TypeScript
- Paste a JSON sample, ideally a real API response, or open a .json file.
- Check TypeScript is chosen as the language, and give the top type a name such as Order or ApiResponse.
- Read the interfaces: one for the top level and one for each nested object.
- Copy them into your project, or download them as a .ts file.
How your files stay private
The workbench runs entirely in your browser: what you paste or open is read, checked and converted in your device's memory. The page can connect only to this site and to Google Analytics, which counts visits and never receives your data. YAML support is a small file loaded from this site the first time you use it. Nothing is saved: closing the tab clears everything.
Limits
- Files up to 20 MB; very large documents can be slow on older phones
- JSONPath supports the common syntax - children, wildcards, .., indexes, slices and filters with comparisons - but not functions
- Arrays are compared position by position, so an item inserted near the start shows as many changes
- Generated code describes the shape of your sample; check optional and nullable fields against your real data
Questions
Is the generated TypeScript free to use?
Yes. The interfaces are yours to use in any project, commercial or not.
Is my JSON uploaded?
No. The types are generated in your browser on your own device - useful when the sample contains real customer or account data.
Does it use interfaces or types?
Interfaces for objects, and a type alias when the top level is an array or a plain value.
How are optional fields detected?
A field that's missing from some objects in an array is marked optional; a field that's null in some is typed with | null.
Can I get Python, Go, C# or Java instead?
Yes. Choose the language above the result; the same sample produces each of them.
Is my JSON uploaded?
No. Everything happens in your browser on your own device, so API responses, configuration files and customer data never leave it.
Other tools you might need
Compress PDF
Reduce the size of image-heavy PDFs and scanned documents.PDF Maker
Photos and PDFs into one PDF - arrange, number and fit a size limit in one go.Encoder & Decoder
Base64, URL and HTML encoding, hex and Unicode, JWT decoding and file hashes, in one place.Timestamp Converter
Unix time to date and back, time zones, date differences, log timestamps and cron schedules.