JSON → Struct / Class
Generate typed declarations from JSON in TypeScript, Python @dataclass, PHP class, Ruby Struct, Go struct, Rust serde, and Java POJO.
TypeScript interface
export interface Profile {
name: string;
age: number;
}
export interface Root {
id: number;
email: string;
active: boolean;
tags: string[];
profile: Profile;
lastLogin: null;
}Python @dataclass
from dataclasses import dataclass
from typing import List, Optional
@dataclass
class Profile:
name: str
age: int
@dataclass
class Root:
id: int
email: str
active: bool
tags: List[str]
profile: Profile
lastLogin: None = NonePHP typed class
class Profile {
public string $name;
public int $age;
}
class Root {
public int $id;
public string $email;
public bool $active;
public array $tags;
public Profile $profile;
public mixed $last_login;
}Ruby Struct
Profile = Struct.new(:name, :age) do # add methods here end Root = Struct.new(:id, :email, :active, :tags, :profile, :last_login) do # add methods here end
Go struct (json tags)
type Profile struct {
Name string `json:"name"`
Age int `json:"age"`
}
type Root struct {
Id int `json:"id"`
Email string `json:"email"`
Active bool `json:"active"`
Tags []string `json:"tags"`
Profile Profile `json:"profile"`
LastLogin any `json:"lastLogin,omitempty"`
}Rust serde struct
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Profile {
pub name: String,
pub age: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub email: String,
pub active: bool,
pub tags: Vec<String>,
pub profile: Profile,
#[serde(rename = "lastLogin")]
pub last_login: serde_json::Value,
}Java POJO (Jackson)
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Profile {
public String name;
public int age;
}
public class Root {
public int id;
public String email;
public boolean active;
public List<String> tags;
public Profile profile;
public Object lastLogin;
}What you get
A typed declaration of your JSON in every major language — TypeScript interface, Python @dataclass, PHP class with typed properties, Ruby Struct, Go struct with json: tags, Rust #[derive(Serialize, Deserialize)], and Java POJO with Jackson annotations.
Array handling
When an array contains objects, the element shape is extracted into its own type. Pass multiple JSON objects (an array at the top level) to merge their shapes — keys that appear in only some samples are marked optional.
You might also like
- CSV ↔ JSON ConverterConvert CSV to JSON or JSON to CSV with quoted fields and configurable delimiters.
- JSON → Code ObjectRender a JSON sample as a literal in JS, TS, Python, PHP, Ruby, Go, Rust, and Java side by side.
- JSON Schema → TypeScriptEmit TypeScript types from a JSON Schema — enum/oneOf/allOf/$ref/definitions all handled.
- PHP serialize / unserializeConvert between PHP's serialize() format and JSON with a recursive-descent parser.
Used in these workflows
- JSON Sample → TypeScript InterfaceInfer types from a JSON sample and emit a TypeScript interface (with nested types).
- JSON Sample → Python @dataclassInfer types from a JSON sample and emit a Python @dataclass.
- JSON Sample → Go Struct (json tags)Infer types from a JSON sample and emit a Go struct with json tags.