Skip to content
PocketDesk
Your files are processed on your device, never uploaded

JSON to TypeScript

  • On device
Input
Ln 1, Col 11 line0 BUTF-8

Paste, drop or open a file in Input to see the result here.

Waiting for input
  • ⌘Enter Run now
  • ⌘⇧C Copy result
  • ⌘F Find in result
  • Esc Exit full screen
  • Use Ctrl instead of ⌘ on Windows and Linux

How to generate TypeScript from JSON

  1. Paste a sample response into Input, drop a .json file on the page, or press Open file.
  2. The types appear as you type. Change Root name, choose interface or type alias, and turn on Add export if you want to import them.
  3. Select Copy or Download to save types.ts.

If the sample is not valid JSON, you see the line and column of the problem instead of types.

How types are inferred

The tool reads your sample and describes what it sees:

  • Strings, numbers, booleans and null become the matching TypeScript types.
  • Each nested object becomes its own named interface, so the output stays readable.
  • Arrays of objects are merged into one interface. A key found in only some items becomes optional.
  • Mixed values become a union, and an empty array becomes unknown[].
  • Keys that are not valid identifiers, such as my-key, are written in quotes.

Get better results

A sample shows only what it contains. If one field is sometimes a number and sometimes missing, include examples of both, or paste an array with several records so the tool can merge them. Treat the output as a starting point and check it against your API documentation: a sample cannot tell the difference between a Date and a string, or between an enum and a plain string.

Tips

  • Format the sample first with the JSON formatter to make sure it is valid.
  • Explore a large response with the JSON tree viewer and paste only the part you need.
  • Need config instead of types? Try JSON to YAML.
  • Use type alias if you plan to combine the result with unions elsewhere.

Privacy

Real responses can contain private data. The generator runs in your browser and your sample never leaves your device.

Questions

How are optional properties detected?

When you paste an array of objects, any key that is missing from at least one object is marked optional with a question mark.

What happens with mixed types?

Values of different kinds become a union, for example string | number, and null is listed last. Arrays of mixed items become (string | number)[].

Can I choose the name of the main type?

Yes. Change Root name. Nested objects are named after their key in PascalCase, and repeated names get a number such as Item2.

Should I use interface or type?

Both describe object shapes. Interfaces can be extended and merged; type aliases can also name unions. Pick the style your project uses.

Is my JSON uploaded?

No. Types are generated in your browser, and nothing is sent anywhere.

More developer tools