YourTools.
简体中文
Back to the catalog
Tools

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

JSON to code types

Run

Processes in this browser; cancel at any time

Add text first

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

  1. Paste a JSON object or a list of objects, or select “Use example”.
  2. Choose the “Language”: “TypeScript interfaces”, “C# classes (System.Text.Json)”, “Java records (Jackson)”, “Go structs”, “Rust structs (serde)” or “Python dataclasses”.
  3. Set the “Root type name”, which is Root by default. It may contain letters, digits and underscores and must start with a letter.
  4. 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