JSON to TypeScript, Rust, C#, Swift, Kotlin, Java, Go, Python, Zod & JSON Schema Generator
Paste JSON and get TypeScript interfaces, Go structs, Python dataclasses, Zod schemas, Rust structs, C# classes, Swift structs, Kotlin data classes, Java classes, or a JSON Schema in seconds. The tool parses your data, infers types for every field, and generates named types for nested objects. No signup, no server calls, no dependencies.
What is a JSON to TypeScript Generator?
A JSON to TypeScript generator takes a sample JSON object and produces corresponding TypeScript type definitions (interfaces, type aliases, or Zod schemas) by inferring the type of each field. Instead of manually writing types that mirror your API responses or config objects, you paste a representative JSON sample and the tool generates the types automatically. This saves time, reduces errors from manual type definitions going out of sync with actual data, and handles edge cases like nested objects, arrays of mixed types, and nullable fields. The same approach works for Go structs, Python dataclasses, Rust structs, C# classes, Swift structs, Kotlin data classes, Java classes, and JSON Schema.
How to Use
- Paste valid JSON into the input pane on the left, or drag and drop a
.jsonfile - Choose output mode: Interface (default), Type, Schema, Go, Python, Zod, Rust, C#, Swift, Kotlin, or Java
- Copy the generated output with the Copy button, or download as
.ts,.go,.py,.json,.rs,.cs,.swift,.kt, or.java - Paste the types into your project and start using them immediately
Output Modes
Interface mode (default)
Produces standard TypeScript interfaces. Best for API responses, config objects, and when you want declaration merging.
Type alias mode
Produces type declarations. Best for union types, mapped types, and when you need more flexibility in your type definitions.
Schema mode
Produces a JSON Schema (draft-07) from your data. The schema includes typed properties, required field lists, integer vs float detection, and recursive nested object schemas. Download as schema.json for use with validation libraries like Ajv.
Go mode
Produces Go structs with JSON struct tags. Each field gets a PascalCase exported name and a json:"..." tag matching the original key. Optional fields (missing from some array items) include omitempty. Download as generated.go for direct use in your Go project.
Python mode
Produces Python dataclasses with type annotations. Fields use snake_case names, missing fields from array items are typed as Optional[T] = None, and common types are imported from typing. Download as models.py for use in your Python project.
Zod mode
Produces Zod schemas with type inference. Each object becomes a z.object() with typed fields, missing fields use z.optional(), and an inferred TypeScript type is exported. Download as schema.ts for use with Zod validation.
Rust mode
Produces Rust structs with serde derives. Each struct gets #[derive(Serialize, Deserialize)], fields use snake_case names, and #[serde(rename)] is added when the JSON key differs from the field name. Optional fields are wrapped in Option<T>. Download as models.rs for use with serde.
C# mode
Produces C# classes with System.Text.Json attributes. Each property gets [JsonPropertyName("...")], properties use PascalCase names, and optional fields are nullable (T?). Download as Models.cs for use in .NET projects.
Swift mode
Produces Swift Codable structs. Each struct conforms to Codable, properties use camelCase names, and CodingKeys enums are generated when property names differ from JSON keys. Optional fields use T?. Download as Models.swift for use in iOS/macOS projects.
Kotlin mode
Produces Kotlin data classes with kotlinx.serialization annotations. Each class gets @Serializable, properties use camelCase names, and @SerialName("...") preserves original JSON keys. Optional fields are nullable with null defaults. Download as Models.kt for use in Android/Kotlin Multiplatform projects.
Java mode
Produces Java classes with Jackson annotations. Each field gets @JsonProperty("..."), fields use camelCase names, and optional fields are marked @Nullable. Download as Models.java for use in Spring Boot and other Java projects.
Type Inference Rules
The tool maps JSON values to types across all supported languages:
| JSON Value | TypeScript | Go | Python | Rust | C# | Swift | Kotlin | Java | JSON Schema |
|---|---|---|---|---|---|---|---|---|---|
"hello" | string | string | str | String | string | String | String | String | "string" |
42 | number | int | int | i64 | long | Int | Long | long | "integer" |
3.14 | number | float64 | float | f64 | double | Double | Double | double | "number" |
true | boolean | bool | bool | bool | bool | Bool | Boolean | boolean | "boolean" |
null | null | interface{} | Any | serde_json::Value | object | Any? | Any? | Object | "null" |
{} | Record<string, unknown> | map[string]interface{} | dict[str, Any] | HashMap<String, serde_json::Value> | Dictionary<string, object> | [String: Any] | Map<String, Any?> | Map<String, Object> | {} |
[] | unknown[] | []interface{} | list[Any] | Vec<serde_json::Value> | List<object> | [Any] | List<Any?> | List<Object> | {} |
[{ ... }] | TypeName[] | []StructName | list[TypeName] | Vec<StructName> | List<ClassName> | [StructName] | List<DataClass> | List<ClassName> | { "items": { ... } } |
Nested Object Naming
Nested objects get path-based names to avoid collisions. Given this JSON:
{
"user": {
"name": "Alice",
"address": { "city": "NYC" }
}
}
The tool generates:
interface RootUserAddress {
city: string;
}
interface RootUser {
name: string;
address: RootUserAddress;
}
interface Root {
user: RootUser;
}
The naming convention uses the key path in PascalCase: user.address becomes RootUserAddress.
JSON Schema Generation
Switch to Schema mode to generate a JSON Schema (draft-07) from your data:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" },
"address": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
},
"required": ["name", "age", "address"]
}
Key features of Schema mode:
- Distinguishes integers from floats (
42→"integer",3.14→"number") - Marks all present properties as required
- Handles nested objects recursively
- Uses
oneOffor mixed-type arrays - Empty arrays default to
{}(any items), empty objects includeadditionalProperties: true
Go Struct Generation
Switch to Go mode to generate Go structs with JSON struct tags:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
package generated
type RootAddress struct {
City string `json:"city"`
}
type Root struct {
Name string `json:"name"`
Age int `json:"age"`
Address RootAddress `json:"address"`
}
Key features of Go mode:
- PascalCase exported field names from camelCase/snake_case keys
- JSON struct tags preserve original key names
omitemptyadded for optional fields (detected from array item variations)- Nested objects become separate struct types with path-based names
- Empty objects become
map[string]interface{}
Python Dataclass Generation
Switch to Python mode to generate Python dataclasses with type annotations:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
from dataclasses import dataclass, field
from typing import Optional, Any, Dict
@dataclass
class RootAddress:
city: str = ""
@dataclass
class Root:
name: str = ""
age: int = 0
address: RootAddress = field(default_factory=RootAddress)
Key features of Python mode:
- snake_case field names from camelCase/snake_case keys
Optional[T] = Nonefor fields missing from some array items- Nested objects become separate dataclass types
- Empty objects become
Dict[str, Any] - Proper imports from
typingmodule
Zod Schema Generation
Switch to Zod mode to generate Zod schemas with TypeScript type inference:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
import { z } from "zod";
export const RootAddressSchema = z.object({
city: z.string(),
});
export type RootAddress = z.infer<typeof RootAddressSchema>;
export const RootSchema = z.object({
name: z.string(),
age: z.number(),
address: RootAddressSchema,
});
export type Root = z.infer<typeof RootSchema>;
Key features of Zod mode:
- Each object becomes a
z.object()schema - Nested objects get separate named schemas
- Missing fields use
z.optional(T) - TypeScript types inferred via
z.infer - Mixed-type arrays generate
z.union([...])
Rust Struct Generation
Switch to Rust mode to generate structs with serde derives:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct RootAddress {
pub city: String,
}
#[derive(Serialize, Deserialize)]
pub struct Root {
pub name: String,
pub age: i64,
pub address: RootAddress,
}
Key features of Rust mode:
#[derive(Serialize, Deserialize)]on every struct- snake_case field names from camelCase/snake_case keys
#[serde(rename)]when JSON key differs from field nameOption<T>for fields missing from some array items- Nested objects become separate struct types
- Empty objects become
HashMap<String, serde_json::Value>
C# Class Generation
Switch to C# mode to generate classes with System.Text.Json attributes:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class RootAddress
{
[JsonPropertyName("city")]
public string City { get; set; }
}
public class Root
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("age")]
public long Age { get; set; }
[JsonPropertyName("address")]
public RootAddress Address { get; set; }
}
Key features of C# mode:
[JsonPropertyName("key")]on every property- PascalCase property names from camelCase/snake_case keys
- Nullable types (
T?) for optional fields - Nested objects become separate classes
- Empty objects become
Dictionary<string, object>
Swift Struct Generation
Switch to Swift mode to generate Codable structs:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
struct RootAddress: Codable {
var city: String
}
struct Root: Codable {
var name: String
var age: Int
var address: RootAddress
}
Key features of Swift mode:
- Every struct conforms to
Codable - camelCase property names from camelCase/snake_case keys
CodingKeysenum generated when property names differ from JSON keys- Optional types (
T?) for optional fields - Nested objects become separate structs
Kotlin Data Class Generation
Switch to Kotlin mode to generate @Serializable data classes:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName
@Serializable
data class RootAddress(
@SerialName("city")
val city: String
)
@Serializable
data class Root(
@SerialName("name")
val name: String,
@SerialName("age")
val age: Long,
@SerialName("address")
val address: RootAddress
)
Key features of Kotlin mode:
@Serializableon every data class@SerialName("key")preserves original JSON key names- camelCase property names from camelCase/snake_case keys
- Nullable types (
T? = null) for optional fields - Nested objects become separate data classes
Java Class Generation
Switch to Java mode to generate classes with Jackson annotations:
{
"name": "Alice",
"age": 30,
"address": { "city": "NYC" }
}
Produces:
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
public class RootAddress
{
@JsonProperty("city")
private String city;
}
public class Root
{
@JsonProperty("name")
private String name;
@JsonProperty("age")
private long age;
@JsonProperty("address")
private RootAddress address;
}
Key features of Java mode:
@JsonProperty("key")on every field- camelCase field names from camelCase/snake_case keys
@Nullableannotation for optional fields- Nested objects become separate classes
- Empty objects become
Map<String, Object>
Common Use Cases
API Response Types
Paste a sample API response and generate types for your fetch calls. Works with REST APIs, GraphQL responses, and any JSON endpoint.
Config Object Types
Generate types for configuration files, environment variables, or settings objects. The tool handles nested configs with multiple levels of depth.
Mock Data Types
Use sample mock data to generate types for your test fixtures. Ensures your mocks match the actual data shape.
Related Tools
- JSON Formatter: Format and validate JSON before converting
- Data Converter: Convert between JSON, YAML, TOML, and .env formats