TapCub is live — analytics, insights and live chat, free on one platform

Free tool JSON to TypeScript converter for API responses

Turn an API response, config file or log lines into readable types, with nested declarations, merged array items, optional keys and unions.

  • Nested declarations
  • Merges array items
  • Runs locally

Paste JSON, copy the types

The sample is a user with two orders. Replace it with your own; the types update as you type.

Converter

One document, or several separated by new lines (JSON Lines); several are merged. Up to 1 MB.

Generated 3 declaration(s) with 12 properties.
TypeScript
export interface User {
  id: number;
  name: string;
  email: null;
  roles: string[];
  orders: Order[];
}

export interface Order {
  id: string;
  total: number;
  coupon?: string;
  items: Item[];
}

export interface Item {
  sku: string;
  qty: number;
  note?: string;
}

Declarations

3

interface and type blocks.

Properties

12

Across all declarations.

Optional

2

Marked with a question mark.

Review these

  • CheckOnly null was seen for email. Replace it with the real type, such as string | null.
Runs entirely in your browser. Nothing you type here is uploaded or stored by TapCub.

Use this tool often? Save it to My tools.Saved to My tools. Find it any time at the top of the free tools page. You can also press Ctrl+D to bookmark this page in your browser.You can also press ⌘+D to bookmark this page in your browser.You can also tap your browser’s Share button (at the bottom in Safari) and choose Add Bookmark or Add to Home Screen.You can also open the ⋮ menu at the top right and tap ☆ to bookmark it, or choose Add to Home screen.You can also tap ··· at the top right and choose Favorite, or open it in your browser and bookmark it there.

Problem or suggestion?Send feedbackChat with support

Version v1.0Updated Update history

Read the types

How each rule was applied

The converter only knows your sample. These rules turn what it saw into types.

  • interface or type
  • Optional keys inferred from arrays
  • Syntax errors with line and column
JSON to TypeScript illustration: Turn JSON into TypeScript interfaces or type aliases, with merged arrays, optional keys and nested types
JSON to TypeScript, illustrated

Optional keys

When several objects share a position, such as the two orders, a key missing from any of them gets ?. In the sample that is coupon and note.

null

A value that is null stays in the union, for example string | null. A field that was only ever null is typed null and listed for review.

Arrays

All items are merged into one element type. Arrays of mixed kinds become a union in parentheses, such as (string | number)[].

Names

Nested types are named after the key in PascalCase, singular for array items. A clash with a different shape gets the parent name in front.

Dictionaries

An object such as {"1001": …, "1002": …} is a lookup table, not a fixed shape. With the option on it becomes Record<string, Item> instead of one property per ID.

Reused shapes

Two nested objects with exactly the same properties, such as billing and shipping addresses, share one declaration. Turn the option off if you expect them to diverge.

Types describe your sample, not the API contract. A field that never happened to be missing will look required, so paste a few varied records or check the documentation.

How to use it

From response to typed code

Copy, paste, name, done.

  1. 1

    Copy a response

    From the network tab, an API client or a log file. Several records on separate lines give better optional and union detection.

  2. 2

    Name the root

    Use the name your code expects, such as User or OrderList.

  3. 3

    Pick the style

    interface or type, export, readonly, inline nesting.

  4. 4

    Copy or download

    Take the code or save types.ts, then tighten the notes: replace lone nulls and unknown arrays.

Mapping

JSON values and the types they become

The full set of rules is short.

  • JSON has no integer or date types, so numbers become number and ISO timestamps stay string
  • An empty object becomes Record<string, unknown>
  • Keys that are not valid identifiers are quoted, such as "content-type"
  • Names that would collide with built-ins such as Event get a Data suffix
Mapping from JSON to TypeScript
JSON sampleTypeScript
"abc", 12.5, truestring, number, boolean
[1, 2]number[]
[1, "a"](string | number)[]
[]unknown[]
"x" in one record, null in anotherstring | null
key present in some records onlykey?: …
Worked example

The sample user, step by step

The sample produces 3 declarations with 12 properties, 2 of them optional.

How the sample fields were typed
FieldSeen in the sampleGeneratedWhy
User.emailnullnullNo other value to learn from; flagged for review
User.roles"admin", "editor"string[]All strings
Order.total49.5, 120numberJSON has one number type
Order.couponfirst order onlycoupon?: stringMissing from the second order
Item.noteone of two itemsnote?: stringItems from both orders are merged
Common mistakes

Where generated types mislead

Check these before you rely on the output.

One record only

With a single object nothing can look optional or nullable. Paste a list with the awkward cases.

Trusting types at runtime

TypeScript types vanish after compiling. Validate external data with a schema or checks.

IDs as numbers

Snowflake-style IDs exceed safe integers and get rounded. Ask the API to send them as strings.

JavaScript object syntax

Trailing commas, single quotes and comments are not JSON. The error shows the line; the JSON formatter can repair them.

FAQ

JSON to TypeScript questions

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

How do I convert JSON to a TypeScript interface?

Paste the JSON and set the root name. The converter writes one interface for each nested object; copy the code into a .ts file.

Should I use interface or type?

Both describe object shapes. Interfaces can be extended and merged by declaration; type aliases can also name unions and arrays. Follow your project’s convention.

How are optional properties decided?

If several objects appear in the same place and a key is missing from at least one, it becomes optional. A single object gives no evidence, so everything is required.

What happens to null values?

null is kept in a union, such as string | null. With strict null checks that forces your code to handle it.

Why do I get a syntax error?

JSON does not allow trailing commas, comments, single quotes or unquoted keys. The tool shows the line and column where parsing stopped.

How are dates typed?

As string. JSON has no date type, and converting them to Date would be wrong unless your code parses them. Change the type by hand after you add the parsing step.

Can I paste several records?

Yes. Separate documents with new lines, or paste an array. They are merged, which improves optional and union detection.

Is my data uploaded?

No. Conversion happens in your browser and the page has no share link. Still remove tokens and personal data before pasting into any online tool.

Feedback

Is this tool working for you?

Rate it, or tell us what went wrong and what you’d like improved. A person reads every message, and frequent requests go into the next update.

Rate this tool

Please don’t include passwords or other sensitive information.

Only used to reply to this feedback.

Type, details and email are required.

We only use this to handle your feedback. See the privacy policy.

Feedback received

Thank you! We will read it and reply from hello@tapcub.com if needed.

Need help right now?

Chat with our support team, best for urgent problems; you can leave a message when we are offline.

Chat with support
Changelog

Update history

New features, fixes and data refreshes for this tool, newest first.

  1. · v1.0

    LaunchedFirst release.

Missing something or found an error? Tell us — requests that come up often go into the next update. All tool updates

Cite this tool

Recommend this tool in an article or on your site

This tool is free to cite and share. Copy the URL or link below into your article, tutorial or resource page; to write a review, embed a tool or partner with us, get in touch.

URL
https://tapcub.com/tools/json-to-typescript
HTML link
<a href="https://tapcub.com/tools/json-to-typescript">JSON to TypeScript - TapCub</a>

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics