JSON to TypeScript Converter

Generate TypeScript interfaces and types from JSON

What is a JSON to TypeScript Converter?

A JSON to TypeScript converter turns a raw JSON sample into strongly typed TypeScript interfaces (or type aliases). Instead of hand-writing an interface for every API response, config file, or database record, you paste the JSON and get accurate, compile-ready types in a fraction of a second — entirely in your browser.

TypeScript’s whole value proposition is catching mistakes before they reach production. But that only works if your data is typed. Most real-world JSON — REST responses, GraphQL payloads, webhook bodies, package.json-style config — arrives untyped, and transcribing it by hand is tedious and error-prone. This tool automates the boring part: it walks the JSON structure, infers a type for every value, names nested objects sensibly, and emits clean TypeScript you can drop straight into your codebase.

Everything happens client-side. Your JSON never leaves the page, which matters when you’re pasting an internal API response that contains real user data or private field names.

How to Convert JSON to TypeScript

  1. Paste your JSON into the input area above. Both objects and arrays are supported as the top-level value.
  2. Click Convert (or press Ctrl+Enter) to generate the TypeScript.
  3. Adjust the settings if needed: rename the root interface, switch between interface and type output, add the export keyword, or turn on “Nullable → optional”.
  4. Copy the result with the Copy button or Ctrl+Shift+C and paste it into your project.
  5. Clear the workspace with Ctrl+L when you’re done.

For the most accurate results, paste an array of several records rather than a single object. With multiple samples the converter can tell which keys are always present and which are optional, and it merges every field it sees into one interface.

interface vs type: Which Should You Use?

TypeScript gives you two ways to describe an object shape, and this tool can output either:

  • interface is the conventional choice for object shapes. Interfaces support extends, declaration merging, and generally produce clearer error messages. If you’re modeling API responses or domain entities, interfaces are the safe default.
  • type aliases are better when you need to compose the shape into a union (type Result = Success | Failure), an intersection, or a mapped/utility type. If your team lints for consistent type usage or you plan to combine the output with other types, choose type in the settings.

Functionally, interface Foo { id: number } and type Foo = { id: number } are interchangeable for plain object shapes — pick whichever matches your codebase’s conventions.

Handling Optional and Nullable Properties

Two of the most common sources of runtime bugs are missing fields and null fields, and TypeScript models them differently:

  • A missing key (present in some records, absent in others) becomes an optional property: avatar?: string. The converter detects this automatically when you paste an array of objects.
  • A null value becomes part of a union by default: deletedAt: string | null. This preserves the fact that the field exists but may hold null.

If you prefer nullable fields to be modeled as optional instead (deletedAt?: string), enable the Nullable → optional setting. Which convention is “correct” depends on your API: null usually means “the field is present and explicitly empty,” while an optional property means “the field may not be sent at all.” Choose the one that matches your contract.

Common Errors and Edge Cases

  • Invalid JSON. The most frequent issue is a trailing comma, single quotes, or an unquoted key — none of which are legal JSON. The tool reports the exact parse error so you can fix it. Run your text through a JSON formatter or JSON validator first if you’re unsure.
  • A single sample object. With only one record, every key looks required. If your production data has optional fields, the generated types will be too strict. Paste a representative array to fix this.
  • Empty arrays. [] gives the converter nothing to infer from, so it produces unknown[]. Replace it with a populated sample if you need a real element type.
  • Numbers that are really enums or IDs. JSON has a single number type, so "status": 1 becomes number, not a literal union like 0 | 1 | 2. Tighten these by hand if your API uses numeric enums.
  • Dates and other stringly-typed values. ISO timestamps arrive as string. TypeScript can’t know they’re dates — annotate them yourself if you parse them into Date objects downstream.

JSON to TypeScript Use Cases

Developers reach for a JSON-to-TypeScript converter constantly:

  • Typing API responses. Paste a sample response from your backend, GraphQL endpoint, or a third-party API and get an interface to type your fetch result.
  • Config and manifest files. Generate types for tsconfig-style settings, feature flags, or CMS payloads so autocomplete and type-checking work across your app.
  • Mock data and fixtures. Turn test fixtures into types to keep your mocks in sync with the shapes your code expects.
  • Migrating JavaScript to TypeScript. When you’re adding types to an existing codebase, converting the JSON your functions already handle is the fastest way to bootstrap interfaces.

JSON to TypeScript vs JSON Schema

TypeScript types and JSON Schema solve related but distinct problems. TypeScript interfaces give you compile-time safety inside your editor and build — they disappear at runtime. JSON Schema describes the same structure in a portable, language-agnostic format used for runtime validation, documentation, and code generation across languages. If you need to validate incoming data at runtime (not just type it), pair this converter with a schema-based validator. For most front-end and Node.js code, though, generating TypeScript interfaces directly from a JSON sample is the fastest path to type safety — paste, convert, copy, done.

Frequently Asked Questions

How do I convert JSON to a TypeScript interface?

Paste your JSON into the input box and click Convert (or press Ctrl+Enter). The tool parses the JSON, infers a type for every property, and outputs one TypeScript interface per object it finds. Nested objects become their own named interfaces, and the top-level shape is named Root by default. You can rename the root, switch to type aliases, and add the export keyword in the settings panel.

Does this tool send my JSON to a server?

No. The entire conversion runs in your browser using JavaScript. Your JSON is parsed and turned into TypeScript locally — nothing is uploaded, logged, or stored on any server. You can confirm this by opening your browser's network tab: there are no requests while you convert. That makes it safe for API responses that contain internal fields or sample data.

How are optional properties detected?

Optionality is inferred when your JSON is an array of objects. If a key appears in some elements but not others, it is marked optional with a question mark (for example name?: string). A single object has no way to signal which fields are optional, so paste an array with several representative records to get accurate optional flags. You can also enable 'Nullable → optional' to treat null values as optional properties.

What is the difference between interface and type output?

Both describe the same shape. An interface (interface User { ... }) is the idiomatic choice for object shapes and supports declaration merging and extends. A type alias (type User = { ... }) is more flexible for unions, intersections, and mapped types. This tool defaults to interfaces; switch to type in the settings if your codebase prefers aliases or you need to compose the result into a union.

How does it handle arrays with mixed types?

The converter looks at every element in an array and produces a union of the types it sees. An array like [1, "a", true] becomes (number | string | boolean)[]. An empty array becomes unknown[] because there is no element to infer from. Arrays of objects are merged into a single interface so that all keys across all elements are represented, with missing keys marked optional.

What happens to property names that aren't valid identifiers?

Keys such as user-id, 2fa, or content-type are not valid JavaScript identifiers, so the tool quotes them in the output ("user-id": number). Object type names derived from these keys are sanitized into valid PascalCase identifiers. Your data is never altered — only the generated TypeScript is adjusted so it compiles cleanly.

Is the generated TypeScript ready to use in production?

The output is valid, compile-ready TypeScript you can paste straight into a .d.ts file or a module. Because types are inferred from a sample, always review the result against your API contract — a field that is always a number in your sample might be nullable in production. Use a representative array of records and the nullable option to tighten the types before shipping.