Skip to content

JSON to TypeScript

Generate TypeScript interfaces from JSON.

  • Free
  • No sign-up
  • No watermark
  • Works in your browser

Also called: JSON to TS interface, JSON to TypeScript types.

About JSON to TypeScript

Turn a JSON document into TypeScript types. Paste the JSON that an API returns, or a list of several sample objects, and the tool writes interfaces (or type aliases) you can paste straight into your code. Nested objects get their own named interfaces, properties missing from some samples become optional, and values that are sometimes null get a union with null.

How to use JSON to TypeScript

  1. Paste your JSON, or press Sample to try an example with a nested address and a list of orders.
  2. Set the Root type name, and choose Declare with interface or type alias.
  3. Choose whether nested objects get Separate declarations or are written Inline, and tick Add export or Readonly properties if you want them.
  4. Copy the TypeScript, or press Download to save types.ts.

Tips and good to know

  • With Top-level array = list of samples ticked, each item of a top-level array is merged into one type that describes a single item. Clear it to get a type for the array itself.
  • Nested interfaces are named after the property: a property called orders holding objects becomes Order[]. If two names clash the second gets a number, such as Item2.
  • A property is required only if it appears in every sample. Add more samples that show the optional cases to get better optional markers.
  • Every number becomes number, because TypeScript has no separate integer type. An empty array becomes unknown[] and an empty object becomes Record<string, unknown>.
  • Property names that are not valid identifiers, such as first-name, are written in quotes.
  • Types are worked out from the examples you give. They cannot know about values you did not show, such as a field that is sometimes a string, so check the result against the API documentation.

Frequently asked questions

Is the generated type exactly right?

It matches the sample data you pasted. Real data may have cases your sample did not show, so treat the result as a very good first draft and adjust it.

Should I use interface or type?

For plain object shapes they behave almost the same. Interfaces can be extended and merged, and type aliases can also name unions and arrays. A top-level array is always written as a type alias, because an interface cannot be an array.

Why is a property marked optional with a question mark?

It was missing from at least one of your sample objects. Paste a list of objects, not a single one, so the tool can see which properties are always there.

Does it create runtime checks?

No. TypeScript types exist only while you write and compile code. To check data while the program runs you need a validator, for example one built from a JSON Schema.

Is my JSON uploaded?

No. Everything runs in your browser and nothing is sent or stored.

Is JSON to TypeScript free?

Yes. JSON to TypeScript is free: no sign-up, no paid plan, no trial and no limit on how often you use it. It runs in your browser, and ToolzAura is paid for by ads, so every tool stays free.

Are my files uploaded?

No. This tool runs in your browser, so your input stays on your device.

Maintained by Malik Shaheer · Last reviewed · How we test tools · Report a problem

Related tools

JSON to YAML

Convert JSON to YAML.

Developer Tools

JSON Tree Viewer

Explore JSON as a collapsible tree.

Developer Tools

JSON Validator

Check JSON syntax and point to the error.

Developer Tools

SQL Formatter

Format SQL queries for readability.

Developer Tools

XML Formatter

Pretty-print XML.

Developer Tools

XML to JSON

Convert XML documents to JSON.

Developer Tools