JSON to Class Converter
A Chrome extension that converts JSON into class definitions for TypeScript, C#, Python and Java — quick model/DTO scaffolding for developers.
What makes it good
- 1Convert JSON into classes for TypeScript, C#, Python and Java
- 2Speeds up DTO and model scaffolding
- 3Published on the Chrome Web Store
How it works
How it works
The converter runs in two separate phases. It walks the JSON once to build a model of class shapes, then a per-language printer turns that model into source.
const model = infer(parsed, rootName); // shapes, types, nullability
const { imports, blocks } = EMITTERS[lang](model, options);
return [imports.join('\n'), blocks.join('\n\n')].join('\n\n');Keeping the two apart matters more than it sounds. A generator that recurses and prints simultaneously ends up re-emitting the file header for every nested class — which is exactly how you get C# output with using System; buried in the middle of the file.
What the inference actually does
Widening across every sample. An array of objects is folded into one representative shape, so a field present on only some elements becomes optional rather than being dropped or wrongly required:
[{ "id": "a1", "total": 10 },
{ "id": "a2", "total": 12.5, "couponCode": "SAVE10" }]export interface Order {
id: string;
total: number; // int + float widened to float
couponCode?: string; // absent on one element
}Format detection. JSON has no date type, so an ISO timestamp arrives as a plain string. Inference recognises ISO-8601 datetimes and dates, UUIDs and emails, and maps each to whatever the target language actually has — pulling in the matching import only when the type is used.
public class User
{
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("id")]
public Guid Id { get; set; }
}Identifier sanitising. JSON keys are not identifiers. first-name, 2fa and class are all legal keys and none of them parse as a field name, so each is rewritten and the round-trip attribute is emitted alongside it:
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
#[serde(rename = "first-name")]
pub first_name: String,
pub class_: String,
}Sixteen targets
TypeScript, C#, Java, Python, PHP, Kotlin, Swift, Go, Rust, Dart, Ruby, C++, SQL, JSON Schema, Zod and Protobuf. A few earn their place by doing more than renaming types — Dart emits the fromJson/toJson pair Flutter developers otherwise hand-write:
factory Order.fromJson(Map<String, dynamic> json) => Order(
sku: json['sku'] as String,
qty: json['qty'] as int,
createdAt: DateTime.parse(json['createdAt'] as String),
);SQL emits one table per class, turning nested objects into foreign keys and arrays of objects into child tables — with reserved words like order quoted so the statement actually executes.
The interface
Chrome caps extension popups at 800×600, so the layout is two panes inside that budget: JSON on the left, generated code on the right, each scrolling independently. Parse errors report line and column rather than a raw offset.