JSON to Types
Turn a JSON sample into types for TypeScript, Zod, C#, Java, Kotlin, Go, Python, Rust, Swift, Dart, PHP or JavaScript, with optional and nullable fields worked out.
JSON to Types
JSON sample
TypeScript types
Paste a JSON sample to get types for it. The more varied the sample, the more accurate the types.
Runs in your browser — nothing you enter leaves this device.
About this tool
What it does
This tool reads a JSON sample — an API response, a config file, a webhook payload — and writes the types that describe it, in TypeScript, Zod, C#, Java, Kotlin, Go, Python, Rust, Swift, Dart, PHP or JavaScript (JSDoc). It looks at every item in every list, not just the first, so a field that is missing from some items comes out optional, a field that is sometimes null comes out nullable, and a list that mixes numbers and strings gets a union. Nested objects become their own named types, named after the key that holds them, and two objects with the same shape share one type instead of being written out twice.
How to use it
- Paste a JSON sample on the left, or press “Try an example”.
- Choose a language. TypeScript gives interfaces, Zod a runtime schema; C# uses System.Text.Json, Java records with Jackson, Kotlin kotlinx.serialization, Go struct tags, Python Pydantic models, Rust serde, Swift Codable, Dart json_serializable.
- Set the root type name — the name of the outermost type, such as User or OrderResponse.
- For TypeScript, turn on “Use type aliases” if your codebase prefers type over interface.
- Copy the code into your project and adjust anything your sample could not show.
Limits and your data
- Types come from the sample, so they are only as complete as it is. A field that is null in every item is typed as null; a list that is empty is typed as unknown[]. Paste a response that shows the real variety.
- Every string is typed as string. The tool does not guess dates, email addresses or enums from a few values, because a guess that is wrong is worse than a plain string you can narrow yourself.
- Whole numbers and decimals are told apart as written: 7 becomes an integer type (long, int64, i64…) and 7.0 or 7.5 a floating-point one. A field holding both is floating point. TypeScript and Zod use number for both.
- A value whose type differs between items (sometimes a string, sometimes a number) becomes the language’s “any JSON” type — JsonElement, JsonNode, any, serde_json::Value — rather than a guess.
- Type names come from keys: orders becomes Order, categories becomes Category. When two different shapes share a name, the second gets a number, such as Meta2.
- The sample can be up to 2 MB.
- The sample is parsed and the code is written in your browser. Nothing is uploaded, so you can paste real responses, but it is still good practice to remove tokens and personal data from anything you commit.
Questions
Why is a field marked optional when my API always sends it?
Because at least one item in the sample did not have it. If the API really always sends it, the sample was incomplete; remove the question mark, or paste a sample where every item has the field.
What is the difference between the TypeScript and Zod output?
TypeScript types exist only while you write code and are removed when it is compiled. A Zod schema also runs: it checks data at runtime, for example a response from a server you do not control, and its inferred type gives you the same TypeScript type from one definition.
Does it handle keys with dashes or spaces?
Yes. TypeScript and Zod keep them in quotes, such as "content-type": string. Other languages get a valid name (ContentType, content_type) and keep the JSON key in an annotation — [JsonPropertyName], @JsonProperty, @SerialName, a struct tag, a Pydantic alias, #[serde(rename)] or CodingKeys — so the data still maps both ways.
Can I generate a JSON Schema instead?
Not here. For checking data against a JSON Schema you already have, use the JSON Schema Validator.