JSON to code types
Generate TypeScript interfaces, C# classes, Java records, Go structs, Rust serde structs or Python dataclasses from sample JSON. Fields missing from some samples become optional.
Process locally
Files stay in this browser session. Closing or clearing releases them.
Add text
Type or paste the text to process
Adjust settings
Optional: Language, Root type name
Run
Processes in this browser; cancel at any time
About this tool
Generate type definitions from sample JSON: TypeScript interfaces, C# classes, Java records, Go structs, Rust serde structs or Python dataclasses. Paste an API response or a config file and get a starting point for your models instead of writing every field by hand.
Nested objects become their own types named after their keys. Lists of objects are merged, so fields missing from some items become optional, and fields that are null become nullable. Field names follow each language’s conventions, with the original JSON key kept in an attribute, tag or comment where needed. Up to 1 MB of JSON is processed in your browser and is not uploaded.
How to use it
- Paste a JSON object or a list of objects, or select “Use example”.
- Choose the “Language”: “TypeScript interfaces”, “C# classes (System.Text.Json)”, “Java records (Jackson)”, “Go structs”, “Rust structs (serde)” or “Python dataclasses”.
- Set the “Root type name”, which is Root by default. It may contain letters, digits and underscores and must start with a letter.
- Select “Run”, then preview the code and download it as a file named after the root type, such as Root.ts.
Formats and limits
- Input
- Text
- Output
- TypeScript, C#, Java, Go, Rust, Python
- Size limit
- 1 MB
- Settings
- Language (TypeScript interfaces, C# classes, Java records, Go structs, Rust structs, Python dataclasses); Root type name
- Privacy
- Files stay in the current browser session. No file bytes are uploaded.
- Price
- Free, no sign-up
Common questions
How are optional and nullable fields decided?
Objects that appear in a list are merged: a field missing from some of them is marked optional, and a field that is null in any sample is nullable. Several representative samples give the most accurate types.
Why is a field typed unknown, object or any?
Its samples were always null or mixed types such as a number and a string, so no single type fits; the items of an empty list get the same treatment. A mix of whole numbers and decimals becomes a floating-point type instead.
Why did 10.0 become an integer type?
In JSON, 10.0 and 10 are the same number, so both count as whole numbers. If a field can hold decimals, include a sample with a fractional part, such as 9.5.
How are nested types named?
Each nested object becomes a type named after its key in PascalCase, and list items take the singular form, so orders gives Order and categories gives Category. A repeated name gets a number, such as Address2, and the items of a list at the root are named after the root type plus Item, such as RootItem.
Why is my JSON rejected?
The input must be strict JSON with an object or a list of objects at the top, so comments, trailing commas and single quotes cause an error. Clean them up first with “Repair and format” in JSON format and validate. Nesting deeper than 64 levels or more than 500 generated types also stops the run.
Workflows that use this tool
Related tools
Code formatter
Format or minify HTML, CSS, SCSS, Less, JavaScript, TypeScript, JSON, Markdown, YAML, XML, SQL, C, C++, C#, Java, PHP, Python and nginx configuration.
Key-value pairs to code
Turn key=value or key: value lines into JSON, YAML, .properties, .env, TypeScript, Python, PHP, Java, C#, Go, HTML options or SQL.
JSON format and validate
Format, minify or sort JSON, repair common mistakes, or escape it as a string. Errors show the line and column, and large numbers keep every digit.
JSON, YAML and XML converter
Validate, pretty-print or convert between JSON, YAML and XML for their shared subset. External entities and custom tags are rejected.
URL parse and query convert
Split a URL into its parts and parameters, turn a query string into JSON, or build a query string from a JSON object.
Convert dates and time zones
Convert one date-time per line between ISO 8601, Unix time and local time in named time zones. Daylight-saving gaps and repeats are reported.