
JSON to TypeScript
Turn a JSON sample into TypeScript interfaces.
Runs in your browser. Nothing you type is uploaded.
How the converter works
Paste a JSON sample and the TypeScript appears as you type. Each object becomes aninterface (or a type alias, if you prefer), property names are kept exactly as they appear in the JSON, and names that are not valid identifiers, such ascontent-type, are quoted.
How types are chosen
- Whole numbers and decimals are both
number. Strings and booleans map directly. - A
nullvalue is typednull. If a field is sometimesnulland sometimes a value, you get a union such asstring | null. - Arrays of objects are merged into one interface. Fields that are missing from some items become optional (
name?: string). - Different types in the same place become a union:
[1, "a"]gives(number | string)[], and a field that is sometimes a number and sometimes a string givesnumber | string. - Empty arrays become
unknown[], and empty objects becomeRecord<string, unknown>, because the sample shows nothing about what they hold. - Nested objects get their own named interface, or choose Inline to keep them inside the parent. Tick export to add the keyword to every declaration.
FAQ
Interface or type?
For plain data shapes they behave almost the same. Interfaces can be extended and merged; type aliases can also name unions. Pick whichever your project already uses.
Will the types match my real data?
The converter only sees your sample, so it cannot know every case. Check optional fields and values that can be several types, and add a validation library such as Zod if the data comes from outside your control.
Is my JSON sent anywhere?
No. The conversion runs in your browser, so your data stays on your device.
More JSON tools
- JSON formatter: Format, minify and validate JSON in one place.
- JSON validator: Check JSON syntax and find the exact line and column of an error.
- JSON beautifier: Pretty print JSON with 2 spaces, 4 spaces or tabs.
- JSON minifier: Strip whitespace to make JSON as small as possible.
- JSON to Go struct: Generate Go struct definitions with json tags from a JSON sample.
- JSON to Python: Generate Pydantic models, dataclasses or TypedDicts from a JSON sample.
- JSON to Rust: Generate Rust structs with serde derives from a JSON sample.