free tool · no sign-up · runs in your browser

JSON to TypeScript interfaces

Paste a JSON sample, like an API response, and get TypeScript interfaces for it. Nested objects become named interfaces, arrays of objects are merged so every key any item has is covered, and keys some items lack are marked optional. Comments and trailing commas in the JSON are fine.

paste here

result

3 types

On a Mac? Skip this tab next time. Pastely does it in any app: copy, press ⌘⇧V, and it pastes in the format that app needs.

Download Pastely free

Free to embed. Put this json to typescript on your blog, docs or class page.

How types are inferred

JSONTypeScript
"text"string
42, 3.5number
trueboolean
nullnull
[1, 2]number[]
[{"id": 1}, {"id": 2, "tag": "a"}]Item[] with tag?: string
{"user": {…}}a separate User interface
[1, "a"](number | string)[]

Naming

Each nested object is named after its key in PascalCase, and objects inside arrays use the singular: devices gives Device, categories gives Category. Change the root type name above, and rename the rest in your editor if a guess reads oddly.

JSON to TypeScript: questions

How does it decide which fields are optional?+

A key is optional when some objects in an array have it and others don't. One object can't show which keys are sometimes missing, so paste an array with several items for the best result.

How are null values typed?+

A value that's always null in the sample is typed null. One that's null in some items and a value in others becomes, for example, string | null.

Does this check my data at runtime?+

No. TypeScript types disappear when the code is compiled. To check data from an API while the app runs, describe it with a schema library such as Zod and infer the type from the schema.

Is my JSON uploaded?+

No. It's parsed and converted in your browser.

More free tools

Paste as Plain Text

Strip fonts, colours and links from copied text, and the invisible characters too.

Remove Line Breaks

Fix text copied from a PDF: join broken lines back into paragraphs.

Case Converter

UPPER, lower, Title, Sentence, camelCase, snake_case and more in one click.

Word Counter

Words, characters, sentences, paragraphs and reading time as you type.

JSON Formatter

Format, validate and minify JSON, and fix trailing commas and single quotes.

Markdown Table Generator

Paste cells from Excel, Google Sheets or a CSV and get a Markdown, HTML or JSON table.

Remove Duplicate Lines

Dedupe, sort, trim and clean up any list in one paste.

Clipboard Viewer

See everything on your clipboard: plain text, HTML, images and hidden formats.

Mac Copy & Paste Shortcuts

Every copy, paste and screenshot shortcut on a Mac, searchable.

Paste Into Google Sheets

Turn any copied table, list or CSV into columns that paste straight into Sheets or Excel.

Table Converter

Convert tables between HTML, Markdown, CSV, TSV and JSON, in any direction.

JSON to CSV

Turn a JSON array into CSV or spreadsheet cells, nested objects flattened.

CSV to JSON

Turn a CSV or spreadsheet into a JSON array, with numbers and true/false typed.

ChatGPT Text Formatter

Fix the asterisks and hashes when you paste ChatGPT text into WhatsApp, Slack or a plain text box.

Markdown to Rich Text

Copy Markdown as real formatting for Google Docs, Gmail, Word and Notes.

Rich Text to Markdown

Paste from Google Docs, Word or a web page and get clean Markdown.

JSON to Swift

Generate Swift Codable structs from JSON, with CodingKeys for snake_case.

Character Counter

Count characters for X, Instagram, meta tags and SMS, including how many texts a message costs.

Sort Alphabetically

Sort any list A to Z, Z to A, by length or in natural number order.