Skip to content
UniKit

JSON to code

Infer types from JSON and generate a TypeScript interface, Java class, Go struct, Python dataclass, Rust struct, C# class or Swift struct.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Generated code
export interface RootOwner {
  email: string;
}

export interface Root {
  id: number;
  name: string;
  tags: string[];
  owner: RootOwner;
}
Inferred types
RootOwner
  • emailstring
Root
  • idnumber
  • namestring
  • tagsstring[]
  • ownerRootOwner

What this tool does

  • Take an API response and generate a TypeScript interface, Java class, Go struct, Python dataclass, Rust struct, C# class or Swift struct in one shot instead of typing the shape by hand.
  • Add types to a frontend project: paste a sample response to get an interface, replace your any, and let the compiler catch wrong field names.
  • Integrating a third-party API: generate the DTO from a sample first, then adjust naming and attributes to match your conventions.
  • Compare modelling styles: generate the same JSON as several languages at once when choosing a stack or writing documentation.

Example

Input

Target language TypeScript, root type name Root, JSON {"id":1,"name":"UniKit","tags":["tools","web"],"owner":{"email":"ada@example.com"}}

Output

export interface RootOwner {
  email: string;
}

export interface Root {
  id: number;
  name: string;
  tags: string[];
  owner: RootOwner;
}

Nested objects get their own type named after the path (RootOwner) and arrays become string[]. Java, Go, Python, Rust, C# and Swift keep integers and floats apart — id becomes int64, i64 or Int — and Go also emits json struct tags.

Frequently asked questions

How are the types inferred?

Purely from the sample JSON you provide: numbers map to numeric types (Java, Go, Python, Rust, C# and Swift keep integers and floats apart), strings to string, booleans to bool/boolean and null to a nullable type. The tool cannot guess your database or API docs, so make the sample representative.

What happens if array items have different types?

When a single array mixes types such as [1,"a"], the element type cannot be pinned down and collapses to a loose type like any or unknown. Use a sample whose array items share the same shape to get precise types. If some objects in an array are missing a field, that field is marked optional.

Can the root be an array?

No — the root value must be a JSON object, otherwise you get "the root value must be a JSON object". With an array, take one element first with the JSON array splitter, or wrap it manually as {"list": […]}.

Will the generated code compile as-is?

Usually yes, but adjust it to your conventions: a Java public class needs to live in a file with the same name, Go needs the right package name, Rust needs the serde dependency, and Swift uses a struct rather than a class. The generated types are a starting point; comments and validation are still yours to add.

Is the data uploaded?

No. Parsing and code generation run entirely in your browser, no network request is made, it works offline, and API payloads are never uploaded or logged.

Keywords:jsonto codetypescriptjavagopythonrustcsharpswiftinterfacestructdataclass类型推断生成代码

Related tools