nicetool.dev logo

JSON to TypeScript

Paste a JSON response or object. Types update as you type.

JSON
Generated code
export interface User {
  id: number;
  name: string;
  email: string;
  score: number;
  active: boolean;
  tags: string[];
  address: Address;
  orders: Order[];
}

export interface Address {
  city: string;
  postcode: null;
}

export interface Order {
  id: number;
  total: number;
  paidAt?: string;
  coupon?: string;
}

Why generate types from JSON?

APIs, config files and webhooks deliver JSON, but TypeScript, Go and runtime validators need an explicit shape. Writing interfaces by hand for a large response is slow and error-prone: a field that is sometimes missing, a number that is sometimes null, or a nested array of objects is easy to get wrong. This tool reads a real sample and infers the structure for you. Arrays of objects are merged, so keys that appear in only some items become optional, keys that are sometimes null become nullable, and every nested object gets its own named type.

Features

  • • TypeScript interfaces or type aliases with optional (?) fields
  • • Go structs with json tags, omitempty and idiomatic names (ID, URL)
  • • Zod schemas with inferred TypeScript types, ordered so references resolve
  • • Merges arrays of objects and detects null, mixed and integer values
  • • Quotes keys that are not valid identifiers, such as "first-name"

Your data stays private

Parsing and code generation run in your browser. API responses with real customer data never leave your machine.

No upload, works offline.

How to use the JSON to TypeScript

  1. 1

    Paste a JSON sample, for example a response copied from the browser Network tab, Postman or curl. The more array items it contains, the better optional fields are detected.

  2. 2

    Pick the output: TypeScript interfaces, Go structs or Zod schemas. For TypeScript you can switch to type aliases.

  3. 3

    Set the root type name, such as User or OrderResponse. Nested objects are named after their keys, and array items use the singular form (orders becomes Order).

  4. 4

    Review the result, adjust anything the sample could not reveal (for example a string that is really a date or an enum), then copy it into your code.

Practical examples

Typing a REST API response

Paste the JSON from GET /api/users/42 and get a User interface with a nested Address type, ready to use with fetch or axios.

Go client for a third-party API

Generate structs with json tags for a Stripe or GitHub webhook payload. Optional keys get omitempty and nested objects become separate types.

Runtime validation with Zod

Turn a sample request body into a Zod schema and use schema.parse() in a Next.js route handler to reject malformed input, with z.infer for the static type.

Config files

Paste a package-specific JSON config to get a typed interface, so editors autocomplete keys and catch typos.

Frequently asked questions

How are optional fields detected?+

When the root or a nested value is an array of objects, all items are merged. A key missing from at least one item is marked optional (? in TypeScript, omitempty in Go, .optional() in Zod).

What happens with null values?+

A key that is null in some items and a string in others becomes string | null (nullable() in Zod, *string in Go). A key that is null in every sample stays null, because its real type cannot be known.

Why is a number typed as int64 in Go?+

Whole numbers in the sample become int64 and decimals float64. If a field mixes both, it is widened to float64 (number in TypeScript).

Can it detect dates, enums or UUIDs?+

No. JSON has no date or enum type, so they appear as string. Refine them by hand, for example with z.string().datetime() or a union of literal values.