JSON to Types Converter (TypeScript, C#, Go, Python, Java)
Paste JSON and get matching type definitions as TypeScript (interface / type), C# classes, Go structs, Python dataclasses, or Java records. Handy for turning an API response example into types or model classes. Nested objects become their own types, and keys missing from some array items become optional (? in TypeScript). To validate or pretty-print the JSON first, use the JSON Formatter.
🔒 Runs in your browser · Your data is never sent to a server
Notes
- Types are inferred from the values in the JSON you paste. Fields that could hold other types but do not in your sample are not reflected, so adjust the result to match your spec.
- All items of an array are merged into one type. Keys present in only some items become optional (? in TypeScript, T? in C#, a pointer with omitempty in Go, "T | None = None" in Python, a reference type in Java).
- Arrays with mixed value types become a union such as (number | string)[] in TypeScript. C#, Go, Python, and Java have no equivalent, so they use object / any / Any / Object.
- An empty array has no known element type, so it becomes unknown[] in TypeScript and a list of object / any / Any / Object elsewhere. A null value is handled the same way. Edit these by hand to the types the field can really take.
- For C#, Go, Python, and Java, numbers without a decimal point become integer types (long / int64 / int) and numbers with one become floating-point types (double / float64 / float). If a field written as 1 in your sample can really be fractional, fix it by hand. TypeScript uses number for everything.
- When a key does not match the naming convention of the language (for example user_id), the property name is converted and the original key is kept in [JsonPropertyName] for C#, a json tag for Go, @JsonProperty (Jackson) for Java, and a comment for Python. A Python dataclass does not map JSON keys by itself, so convert them when loading.
- The Python output uses "|" in type hints, so it needs Python 3.10 or later; the Java output uses records, so it needs Java 16 or later.
Glossary
interface
A TypeScript declaration that describes the shape of an object (property names and types). It supports extending and declaration merging.
type alias
A name for a type. It can describe object shapes as well as unions, tuples, and more. For plain object shapes it is used almost like an interface.
Union type
A type that can be one of several types, such as "string or number". Written string | number.
Optional property
A property marked with ? after its name, which may be absent. Its type includes undefined.
dataclass / record
A concise way to write a class that only holds data. Python has dataclass and Java has record; both generate the constructor and related boilerplate for you.
FAQ
Which languages besides TypeScript can it generate?
C# classes, Go structs with json tags, Python dataclasses, and Java records. Switch the output language with the buttons on the page. In every language, nested objects become their own types.
How are integers and decimals told apart?
For languages other than TypeScript, a value with a decimal point becomes a floating-point type (double / float64 / float) and one without becomes an integer type (long / int64 / int). If an array mixes both, it is treated as floating-point. Fix fields by hand if a value that is an integer in your sample can really be fractional.
What happens when objects in an array have different keys?
All objects in the array are merged into one type. Keys that appear in only some of them become optional properties (marked with ?).
What types do null and empty arrays get?
A null value becomes the null type, and an empty array becomes unknown[] because its element type cannot be inferred. Edit them to match your real API, for example string | null.
Does it work with keys that contain hyphens or digits?
Yes. Keys that are not valid TypeScript identifiers, such as "first-name", are emitted as quoted properties. Nested object types are named after the key in PascalCase.
Share this page
