JSON to Types
Generate C#, TypeScript, Go, Python and 5 more types from JSON.
Runs in your browser
Types are inferred from this sample only. Paste several array items to discover optional fields and mixed types.
Types for your JSON, in your language
Writing classes for an API response by hand is slow and easy to get wrong. Paste a sample response and get ready-to-use types in TypeScript, C#, Go, Python (Pydantic), Java, Kotlin, Rust, Swift (Codable) or Zod. Nested objects become their own named types.
Each language gets its own conventions: C# properties in PascalCase with [JsonPropertyName], Go fields with json tags and ID / URL initialisms, Pydantic fields in snake_case with aliases, Rust structs with serde attributes, Swift structs with CodingKeys. Whole numbers and decimals are told apart (long vs double), and IDs too big for 64 bits get a type that keeps them exact.
How to use the JSON to Types
Paste a JSON sample. A real API response works best, with several array items if it has lists.
Pick your language. The types update instantly, and your choice is remembered next time.
Name the root type. It's
Rootby default; nested types are named after their keys, soitemsgivesItem.Copy it into your project. A comment at the top shows how to parse the JSON into these types.
Tips
- Paste several array items, not just one. Keys missing from some items become optional, and values that are
nullsomewhere become nullable. - Types come only from the sample. A field that's always
nullcan't be guessed, so it becomes a general JSON value (JsonElement,any,serde_json::Value); change it to the real type. - Fields whose values mix types, like
1and"two", become a union in TypeScript and Python, and a general JSON value in languages without unions.
Frequently asked questions
Which C# style does it use?
Classes for System.Text.Json: PascalCase properties with [JsonPropertyName] when the JSON name differs, required for fields that are always present, and ? for optional or nullable ones (C# 11 / .NET 7 or later).
How are optional fields detected?
When an array has several objects, any key missing from at least one of them is optional. Each language marks it its own way: ? in TypeScript, a nullable type in C#, omitempty in Go, = None in Python, Option in Rust.
What happens to very large numbers?
Integers bigger than 64 bits (like some database IDs) get a type that keeps every digit: decimal in C#, json.Number in Go, BigInteger in Java, serde_json::Number in Rust, Decimal in Swift.
Where did JSON to TypeScript go?
It's this tool: TypeScript is still here, with the same interface and type options, alongside seven more languages. The old address redirects here.
Is my JSON uploaded?
No. Types are generated in your browser, so it's safe to paste real API responses.