JSON → Struct / Class
Generate typed declarations from JSON in TypeScript, Python @dataclass, PHP class, Ruby Struct, Go struct, Rust serde, and Java POJO.
export interface Profile {
name: string;
age: number;
}
export interface Root {
id: number;
email: string;
active: boolean;
tags: string[];
profile: Profile;
lastLogin: null;
}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 = Noneclass 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;
}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
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"`
}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,
}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;
}</>Use this tool programmaticallycurl · JavaScript · MCP
Same tool, callable from any HTTP client or from Claude (via MCP). Anonymous: 100 req/day per IP. Sign up for 1,000 req/day.
curl https://api.b-e-a-d.com/tools/json-to-struct/run \
-H "Content-Type: application/json" \
-d '{
"input": "your input here",
"rootName": "Root"
}'const res = await fetch("https://api.b-e-a-d.com/tools/json-to-struct/run", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"input": "your input here",
"rootName": "Root"
}),
});
const data = await res.json();
console.log(data.result);# In Claude Desktop / Claude Code, add to your MCP config:
{
"mcpServers": {
"bead": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.b-e-a-d.com"]
}
}
}
# Then ask Claude to call:
mcp__bead__bead_json_to_structFull reference: developer docs · OpenAPI spec
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.