How JSON Becomes TypeScript Types
A JSON document only shows values, while a TypeScript interface describes every value a field may hold. The converter bridges that gap by reading your whole sample, so the more representative the JSON you paste, the more accurate the types. In a hurry? The JSON to TS page is the short version.
Add your JSON
Paste a JSON object or array into the left editor, upload a .json or .txt file, or press Sample to load a telecom plan with a nested list of subscribers.
Let it read every value
The converter walks the whole document, merging all items of each list, and decides every field’s type from the values it finds. Output appears about half a second after you stop typing.
Read the interfaces
Root describes the top level. Each nested object gets an exported interface named after its key, lists of objects get a singular name (subscribers becomes Subscriber), and a top-level list becomes a type alias.
Copy or download
Copy the code or download types.ts. The first line shows how to type the result of JSON.parse with it.
The Typing Rules
Strings, numbers, booleans. A quoted value is a string, so "00501" keeps its leading zeros. Every JSON number is number, whether it is written 42, 14.50 or 1e3.
Nested objects. Each one gets its own exported interface. Names come from the key in PascalCase; a key that would hide a built-in such as Date or Array gets Data added, and repeated names get a number.
Keys. Property names are copied exactly. Keys that aren't plain identifiers, like "first-name" or "2nd", are written in quotes.
Lists. All items are merged. Missing keys become optional, nulls add | null, and mixed values become unions such as (string | number)[]. An empty list is unknown[].
Only null. A field that is null everywhere in the sample becomes unknown, since nothing shows what it holds otherwise.
Example: Two Products That Don't Quite Match
The two items below disagree: only the second has tags, the discount is null in one, and size is text in one and a number in the other.
[
{ "sku": "A1", "price": 14.50, "zip": "00501", "discount": null, "size": "M" },
{ "sku": "B2", "price": 3, "zip": "10001", "discount": 0.1, "tags": ["sale"], "size": 42 }
]This is the converter's real output. Because the JSON is a list, Root is a type alias and the item shape lives in RootItem:
// Read it with: const data = JSON.parse(text) as Root;
// Your JSON is a list, so Root is a type alias for an array.
export type Root = RootItem[];
export interface RootItem {
sku: string;
price: number;
zip: string;
discount: number | null;
size: string | number;
tags?: string[];
}Frequently Asked Questions
Does it write interfaces or type aliases?
Interfaces for objects, because they read well in editor tooltips and can be extended later. Type aliases are used where an interface can't do the job: a top-level JSON array becomes export type Root = RootItem[], and an object with no keys in your sample becomes Record<string, unknown> so any keys are accepted. You can turn any interface into a type alias by hand without changing what it allows.
What is the difference between an optional field and a nullable one here?
A ? means the key may be missing: it was absent from at least one item of a list. | null means the key is there but its value can be null, because it was null at least once. They are different things in TypeScript, so a field that is sometimes missing and sometimes null gets both, as in note?: string | null.
How are lists of objects merged?
Every item is read, not just the first. Keys from all items end up in one interface, keys that some items lack become optional, and number values stay number whether they are 3 or 14.5. If a field holds different kinds of values across items, say a string in one and a number in another, it becomes a union like string | number.
Will the interfaces check my data when the program runs?
No. TypeScript types disappear when the code is compiled, so JSON.parse(text) as Root only tells the compiler what to expect. If the JSON later has a different shape, nothing stops it. For data from outside your app, pair the types with a runtime check, for example a schema from the JSON to Zod page.
Why do some numbers get a comment about 2^53?
JSON.parse stores numbers as 64-bit floats, which hold whole numbers exactly only up to 9007199254740991. A bigger integer such as 8901240544102066246 is read as 8901240544102066000. The type stays number because that is what JSON.parse returns, and the comment shows the value you will really get. Text in quotes, like "00501", is a string and keeps every character.
Does my JSON leave the browser?
No. Everything runs on this page in your browser. What you paste or upload is not sent to our server and is not kept: reload the page and the editor is empty again.
Not sure your JSON is valid? Check it with the JSON Validator first. For a runtime schema, try JSON to Zod.
Related Tools
JSON to C
Convert JSON data to C structs with parsing functions and memory management
JSON to C++
Convert JSON data to modern C++ classes with STL containers and smart pointers
JSON to C#
Convert JSON data to C# classes with properties and attributes
JSON to Python
Convert JSON data to Python dataclasses with type hints
JSON to Java
Convert JSON data to Java classes with getters, setters, and annotations
JSON to TS
Generate TS (TypeScript) type definitions from JSON data