Skip to content
hateitall

JSON to TypeScript

Paste an API response and get types you can commit, instead of writing them by hand.

Processed locallyIn: JSONOut: TypeScript

Loading tool…

How to use json to typescript

  1. Paste a JSON sample, ideally an array with several records.

  2. Name the root type.

  3. Choose interface or type, export, readonly and how optional keys are written.

  4. Copy the code or download a .ts file.

What this tool does

  • Merges every object in an array, so a key missing from some records becomes optional.
  • Values that are sometimes null or of mixed kinds become unions like string | null.
  • Nested objects get their own named interface, and identical shapes share one name.
  • Keys that are not valid identifiers, such as "avatar-url", are quoted.

How the result is verified

Every value in your sample is checked against the generated type model and must fit before the tick appears.

Frequently asked questions

Why is a field optional when it always exists in production?

It was missing from at least one record in your sample. Add a record that has it, or edit the ? out by hand.

Interface or type?

Both describe the same shape here. Interfaces can be extended and merged, types can be combined with unions; pick the one your codebase uses.

Is my data uploaded to a server?

No. Everything you drop, paste or type is processed by code running in this browser tab. You can check it yourself: open your browser's developer tools, watch the Network panel, and use the tool. No request carries your data.

Infer a JSON Schema from sample data, draft 2020-12 or 07

JSON→ JSON SchemaLight on device

Beautify or minify JSON with your choice of indentation

JSON→ JSONLight on device

Fake JSON records from your own field list, seeded and repeatable

Field list→ JSONLight on device

Live JSONPath queries with filters, slices and match paths

JSON · JSONPath→ JSONLight on device