JSON to TypeScript / C# Types

Generates TypeScript interfaces or C# classes from a sample JSON, inferring nested types and optional and nullable fields.

Loading…

How to use

  1. Paste a sample JSON (for example, an API response) into the input box.
  2. Under Output, choose TypeScript interface or C# class.
  3. Enter the Root type name for the top-level type (Root is used if left empty). If the JSON is an array, its elements become a type named after the root plus Item, such as RootItem.
  4. The code updates as you type. Each nested object becomes its own type named after its key in PascalCase, and objects inside an array get a singular name (items becomes Item).
  5. Press Copy to copy the code. If the input is not valid JSON, Invalid JSON is shown with the parser message.

Frequently asked questions

Is my JSON sent to a server?
No. Types are generated in your browser.
How are optional and nullable fields decided?
Objects in the same array are merged into one type. A field missing from some of them is optional (a ? after the name in TypeScript, a nullable type in C#), and a field that is null somewhere in the sample gets | null in TypeScript and ? in C#.
Which number types are used?
TypeScript uses number for all numbers. In C#, whole numbers become int, whole numbers outside the int range (±2147483647) become long, and numbers with a fraction become double; if a field mixes them, the widest one is used. Note that 1.0 in JSON counts as a whole number.
What happens with mixed arrays, empty arrays and null-only fields?
In TypeScript, values of different kinds become a union such as string | number, so a mixed array becomes (string | number)[]. C# has no unions, so it uses object. An empty array becomes unknown[] or List<object>, and a field that is only ever null becomes null or object?.
How are C# property names chosen?
JSON keys are converted to PascalCase (user_id becomes UserId). When the property name differs from the key, a [JsonPropertyName] attribute for System.Text.Json keeps the original key; in TypeScript, keys that are not valid identifiers are kept in quotes.