Home › Developer Tools › JSON to TypeScript

JSON to TypeScript

Paste a JSON object or API response and get ready-to-use TypeScript interfaces or type aliases, with properly named nested types and optional fields worked out from your data. Conversion runs entirely in your browser.

Last updated:

Your JSON is parsed locally in this tab and never uploaded. Tip: Ctrl + Enter generates.

Advertisement

How to use the JSON to TypeScript

  1. Paste your JSON (an object, an array or an API response) into the left box, or open a .json file.
  2. Name the root type, for example User or ApiResponse.
  3. Pick the options: interface or type alias, export, readonly, optional properties and array style.
  4. Press Generate TypeScript. With Live update on, the output changes as you type.
  5. Copy or download the .ts file and import the types in your project.

Example: from JSON to interfaces

Given this response, where the second post has an extra field and the first has none:

{ "id": 1, "name": "Ada", "deletedAt": null,
  "posts": [ { "id": 1, "title": "Hello" },
             { "id": 2, "title": "Draft", "cover": "a.png" } ] }

the generator produces:

export interface Root {
  id: number;
  name: string;
  deletedAt: null;
  posts: Post[];
}

export interface Post {
  id: number;
  title: string;
  cover?: string;
}

How JSON values map to TypeScript

JSON valueTypeScript type
"text"string
42, 3.14, -1e3number (TypeScript has no separate integer type)
true / falseboolean
nullnull, or T | null when other samples have a value
{ … }A named interface or type
["a", "b"]string[]
[1, "two", null](number | string | null)[]
[]unknown[]
Key missing in some array itemsOptional property key?: T

Tips for accurate types

  • Use real, varied samples. Types are inferred from the data you paste. Include an array with several items so optional fields and nulls show up.
  • Dates stay strings. JSON has no date type, so ISO timestamps are typed as string. Convert them with new Date() after parsing.
  • Narrow string unions by hand. A field like "status": "active" is typed as string; change it to 'active' | 'banned' if you know the possible values.
  • Validate at runtime. TypeScript types disappear after compilation. For untrusted API data, add runtime validation (for example with a schema library) as well.

Need to tidy the JSON first? Use the JSON Formatter or explore it in the JSON Viewer.

Frequently asked questions

How are optional properties detected?

When an array contains several objects, the converter merges them into one type. A key that is present in only some of the items is marked optional with ?, because your data shows it can be missing. With a single example object, every key is required unless you tick All properties optional.

How are null values typed?

A null value adds null to the property's type. If other samples of the same property have a value, you get a union like string | null; if the property is only ever null, its type is just null, and you may want to replace it with the real type by hand.

Interface or type alias: which should I use?

Both describe object shapes equally well. Interfaces can be extended and merged and give slightly clearer error messages; type aliases are needed for unions and mapped types. Many style guides use interfaces for object shapes, which is the default here.

How are nested types named?

Each nested object gets a PascalCase name from its key: profile becomes Profile, avatar_url-style keys become AvatarUrl, and array keys are singularised, so posts becomes Post and categories becomes Category. Clashing names get a number, and objects with exactly the same shape share one type.

What happens with empty arrays and objects?

An empty array becomes unknown[] because there is no item to learn from, and an empty object becomes an empty interface. Add a sample item, or edit the type afterwards.

Are keys with dashes or spaces supported?

Yes. Keys that are not valid JavaScript identifiers, such as email-notifications or 2fa, are written in quotes, for example "email-notifications": boolean.

Is my JSON uploaded?

No. Parsing and type generation are pure JavaScript running in this page, so API responses with personal or secret data stay on your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.CSV to JSONConvert CSV data to JSON with live preview.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.JSON to C# ClassConvert JSON to C# classes or records with System.Text.Json or Newtonsoft attributes.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.VCF to CSV ConverterConvert vCard (.vcf) contacts to CSV for Google or Outlook, or turn a CSV back into a VCF.Calendar Event (.ics) GeneratorCreate an .ics calendar invite with time zone, reminders and repeats + Google/Outlook links.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.INI to JSON ConverterConvert INI and CFG files to JSON and JSON back to INI, with sections, arrays and types.IP Address ConverterConvert IPv4 to decimal, hex, binary, octal and back, with class and private/public check.ISBN Converter & ValidatorConvert ISBN-10 to ISBN-13 and back, validate check digits and hyphenate, one or in bulk.JSON Flatten / UnflattenFlatten nested JSON to dot or bracket path keys, or unflatten flat keys back to nested JSON.JSON to Dart ClassTurn JSON into Dart model classes with fromJson, toJson, null safety and nested classes.JSON to Java ClassTurn JSON into Java POJOs or records with Lombok, getters/setters and Jackson or Gson annotations.JSON to Kotlin Data ClassTurn JSON into Kotlin data classes for kotlinx.serialization, Gson, Moshi or Jackson.JSON to Markdown TableTurn a JSON array of objects into a GitHub Markdown table with column picker and alignment.JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.JSON to Rust StructTurn JSON into Rust structs with serde derives, rename attributes, Option and Vec types.JSON to SQL ConverterConvert a JSON array of objects to CREATE TABLE and INSERT statements for MySQL, Postgres, SQLite.JSON to Swift StructTurn JSON into Swift Codable structs with CodingKeys, optionals and nested types.JSON to TOML ConverterConvert JSON to clean TOML with tables, arrays of tables, inline tables and dates.JSONL to JSON ConverterConvert JSON Lines / NDJSON to a JSON array and back, with line-level error reports.Properties to YAML ConverterConvert Java .properties to nested YAML (application.yml) and YAML back to properties.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.
See all 129 Data & File Format Converters →