JSON to TypeScript Converter

To convert JSON to TypeScript: string values become string, numbers become number, booleans become boolean, null becomes null, objects become interfaces (e.g., {name: "John"} becomes interface Root { name: string; }), and arrays become typed arrays (string[], number[], or Interface[]). Nested objects get their own named interfaces derived from the property key.

Convert JSON to TypeScript interfaces or types instantly. Handles nested objects, arrays, nulls, and optional properties. Customize root name, export keyword, and interface vs type. Presets for API responses, configs, and complex nested data.

Works OfflineDark ModeNo Ads

JSON Input

JSON to TypeScript Type Mapping

JSON ValueTypeScript TypeExample
"hello"stringname: string
42, 3.14numberage: number
true, falsebooleanisActive: boolean
nullnulldata?: null
[1, 2, 3]number[]scores: number[]
["a", "b"]string[]tags: string[]
{...}interfaceaddress: Address
[{...}]Interface[]users: User[]

How to Use

  1. 1

    Paste your JSON

    Paste a JSON object or array into the input area, or click a preset (API Response, Array of Objects, Config File, Nested Complex)

  2. 2

    Configure options

    Set the root interface name, choose interface vs type, toggle export and optional null properties

  3. 3

    Review TypeScript output

    The generated TypeScript interfaces appear instantly with proper typing for all nested structures

  4. 4

    Copy to your project

    Click the copy button to copy the TypeScript definitions to your clipboard and paste into your .ts file

Frequently Asked Questions

How does JSON to TypeScript conversion work?
The converter analyzes your JSON structure and generates TypeScript interfaces (or types) matching the shape of the data. Objects become interfaces with typed properties. Arrays become typed arrays. Nested objects get their own named interfaces. Null values become optional properties with null union types.
Should I use interface or type for JSON conversion?
Use interface when you need declaration merging or extending (common for API responses). Use type for unions, intersections, and computed types. For most JSON-to-TypeScript conversions, interface is the standard choice as it provides better error messages and is more widely used in codebases.
How are arrays of objects handled?
When the JSON contains an array of objects like [{id: 1, name: "Alice"}, {id: 2, name: "Bob"}], the converter merges all objects to create a superset interface. This ensures the generated type includes all possible properties across all array elements.
How are null values converted to TypeScript?
JSON null values are converted to optional properties with a null type union. For example, {"data": null} becomes data?: null. With the "optional nulls" option enabled, null properties use the ? modifier since they may not always be present in the data.
Can I customize the generated TypeScript types?
Yes. You can change the root interface name, toggle between interface and type keywords, enable/disable export, and control whether null properties are marked as optional. These options let you match your project's coding conventions.
How are nested JSON objects named in TypeScript?
Nested objects are given interface names derived from their property key. For example, {"address": {"city": "NY"}} generates an Address interface. Array items use the singularized form of the key: "users" array items become User interface.

Related Tools