ShotMark
Skip to Content

JSON to TypeScript

Generate TypeScript interfaces from any JSON object, paste, get types.

JSON Input
TypeScript Output
Waiting for input

What is JSON to TypeScript?

A JSON to TypeScript converter takes a JSON object and generates the TypeScript interface declarations that describe its shape, inferring the type of every value (string, number, boolean, array, nested object) so you get compile-time type safety for any payload you handle in code. Paste a sample, get an interface you can drop straight into a .ts file.

This JSON to TypeScript tool runs in your browser. It walks the JSON tree, names nested objects automatically, collapses arrays into typed element types, and emits clean interface declarations with the root interface named whatever you set. Frontend developers, full-stack teams, and API consumers use it to skip the tedious step of hand-writing types for every endpoint they call.

Why use this JSON to TypeScript converter?

  • Skip the manual typing tax. Paste a real API response and get the interface in seconds, instead of tabbing through the payload and typing each field by hand.
  • Catch shape bugs at compile time. Once you have the interface, TypeScript flags any field rename, type change, or missing key the moment the API drifts.
  • Customize the root interface name. Set the entry-point name so it matches your domain language (User, Order, WebhookPayload) without renaming after paste.
  • Stay private by default. Generation runs entirely client-side. Your API responses never leave your browser, so test data with PII stays on your machine.
  • Get clean, idiomatic output. Nested objects become separate interfaces with descriptive names, not inline anonymous types, so the result is easy to read and refactor.

How to use the JSON to TypeScript converter

  1. Set the Interface name input to the root type name (defaults to Root).
  2. Paste your JSON sample into the input panel on the left.
  3. Click Convert.
  4. Copy the generated TypeScript from the output panel and paste it into a .ts file.

Type-mapping table

JSON valueTypeScript type
"text"string
42, 3.14number
true, falseboolean
nullnull
{}Generated nested interface
[] (empty)unknown[]
[1, 2] (uniform)number[]
[1, "a"] (mixed)`(number
Array of objectsItem[] with a generated Item interface

The converter does not infer enums or literal types from sample values. A field with the value "active" becomes string, not "active" | "inactive". Refine the generated interface by hand when you need stricter unions.

Worked example

Paste a JSON sample like:

{ "id": 12, "email": "ada@example.com", "active": true, "roles": ["admin", "owner"], "address": { "city": "London", "zip": "W1" } }

With the interface name set to User, the converter produces:

export interface User { id: number; email: string; active: boolean; roles: string[]; address: Address; } export interface Address { city: string; zip: string; }

Drop the output into your codebase, import User, and the rest of your code gets autocomplete and type checks for every field.

Common use cases

  • Frontend developers wiring up a new API. Paste the first response from the backend and get types ready for fetch<User> and React Query.
  • Full-stack teams keeping client and server in sync. Regenerate the interface after a backend schema change to surface every breaking field rename.
  • API consumers writing SDK wrappers. Bootstrap typed client libraries by converting sample responses from documentation into starting interfaces.
  • QA engineers writing typed test fixtures. Generate types for mock data so test files refuse to compile when the API contract changes.
  • Tech writers maintaining type-safe docs. Auto-generate the type sections of API documentation from canonical sample responses.

Frequently asked questions

Why does my array become unknown[]?

Empty arrays in the JSON sample carry no element type information, so the converter falls back to unknown[]. Paste a sample with at least one representative element to get a useful type, or hand-edit the interface afterward.

How does the converter handle optional fields?

It does not infer optionality from a single sample. Every field in the JSON becomes a required property in the generated interface. If some fields are optional in your API, add ? to those properties manually, or paste a richer sample that distinguishes always-present from sometimes-present fields.

Can I generate literal union types from sample values?

Not automatically. A field with the value "admin" becomes string, not "admin" | "owner". To get a strict union, edit the generated interface and replace string with the explicit union. For larger schemas, tools like quicktype offer enum inference if you provide multiple samples.

Does the converter handle nested arrays of objects?

Yes. An array of objects produces a separate interface for the element type and references it as ItemName[]. Deeply nested structures generate as many interfaces as needed, each named from the parent key.

What if my JSON has number-like strings?

The converter types each field based on its actual JSON type. A value like "123" is a string, not a number, even though it looks numeric. If your API sends numbers as strings (common in financial APIs), the type will be string and your code will need to coerce.

How are dates typed?

JSON has no native date type, so date strings come through as string. The converter cannot tell "2026-05-17" from any other string. After generation, retype date fields to Date if you parse them, or to a branded type like IsoDateString for stricter handling.

Can I use the output with zod or other schema libraries?

The output is a plain TypeScript interface, not a runtime schema. To get a runtime validator, hand-translate the interface into a zod schema, or use a code generator that targets zod directly. Interfaces give you compile-time safety only.

Like this tool?

ShotMark captures what you do here, in one click.

The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.

Private beta accessFounding pricing lockNo spam ever