JSON, XML & YAML to Class Generator

Paste a sample document, pick a language and get ready-to-use model classes. Nothing leaves your browser.

What this generator does

Writing model classes by hand for an API response is slow and error-prone: you copy every key, guess every type and then discover that one field is sometimes null. This tool reads a real sample instead. It walks the whole document, infers a type for every field, turns each nested object into its own named class and emits code in the language you pick. It works from three input formats and targets nine outputs:

GenerateWhat you get
C#Classes with { get; set; } properties, [JsonPropertyName] attributes for System.Text.Json, List<T> collections and nullable reference types enabled
JavaPOJOs with private fields, getters and setters, using boxed types (Long, Double) so missing values can be null
GoStructs with exported field names and `json:"..."` tags, aligned the way gofmt would
Python@dataclass classes with type hints plus from_dict / to_dict helpers for nested objects
TypeScriptexport interface declarations, optional keys marked with ?
JavaScriptES classes with a constructor that maps a plain object and builds nested instances
DartFlutter-friendly classes with fromJson factories and toJson methods
Objective-C@interface / @implementation pairs with NSString, NSNumber and NSArray properties
JSON SchemaA draft 2020-12 schema describing the sample, with required lists and nested objects described inline

How to use it

  1. Choose the Input format: JSON, XML or YAML.
  2. Choose what to Generate.
  3. Paste a representative sample. Use a real response with every optional field filled in if you can; the generator can only describe the keys it sees.
  4. Click Generate, then Copy the code into your project.

Links can preselect both menus with ?mode=, for example ?mode=xml-csharp, ?mode=yaml-go or ?mode=json-dart.

Worked example

This JSON sample has a scalar, a null, an array of strings, a nested object and an array of objects:

{ "id": 7, "name": "Ada", "email": null,
  "tags": ["admin", "editor"],
  "address": { "city": "London", "zip": "N1" },
  "orders": [ { "sku": "A1", "qty": 2, "price": 9.5 } ] }

With Go selected, the generator produces three structs. address becomes an Address type, and orders becomes a slice of a singular Order type:

type User struct {
	Id      int64       `json:"id"`
	Name    string      `json:"name"`
	Email   interface{} `json:"email"`
	Tags    []string    `json:"tags"`
	Address Address     `json:"address"`
	Orders  []Order     `json:"orders"`
}

type Order struct {
	Sku   string  `json:"sku"`
	Qty   int64   `json:"qty"`
	Price float64 `json:"price"`
}

Switch to Python and the same sample gives @dataclass class User with id: int, price: float and a from_dict that builds the nested Address and Order objects for you.

How types are inferred

XML and YAML input

For XML, the root element names the top-level class. Attributes and child elements both become fields, text values are typed (7 is a number, true a boolean), and an element that repeats under the same parent becomes a list everywhere it appears, so <tag>a</tag><tag>b</tag> gives List<string> Tag in C#. Namespace declarations are ignored. YAML is parsed with js-yaml using the JSON-compatible schema, so it produces exactly the classes the equivalent JSON would; this is handy for Kubernetes manifests, OpenAPI fragments and config files.

Limits to know about

The output describes one sample, not a contract. A field that happens to be an integer in your sample may be a decimal in production, and keys that never appear in the sample are not generated. For a real contract, generate a JSON Schema from several samples and review it. Dates stay strings, because JSON has no date type. For TypeScript with Zod, Valibot or io-ts, use JSON to TypeScript; for Pydantic models, JSON to Pydantic; for Rust, Kotlin and Swift, the JSON code generator.

Language and format guides

Pick a format and a language in the menus above, or use a ?mode= link. Dedicated pages are kept for the terms people search most: JSON to Dart, JSON to Python, JSON to Java, XML to JavaScript and XML to Python. The guides below cover the other combinations that used to have their own URLs.

JSON to JavaScript classes

Produces ES2020 classes whose constructors copy fields from a plain object, create nested class instances for nested objects and map arrays of objects, with JSDoc type comments and a static fromJSON() helper; the classes are exported as an ES module. For {"id":1,"address":{"city":"Oslo"}} the Root constructor sets this.address = data.address == null ? null : new Address(data.address);. Open with JavaScript selected.

JSON to Objective-C models

Generates an @interface with properties (strings as copy NSString *, numbers and booleans as NSNumber *, arrays as typed NSArray) plus an implementation with initWithDictionary: and dictionaryValue that handle NSNull and nested models. Names that clash with Objective-C (such as id) get a trailing underscore: "id" becomes NSNumber *id_. The code compiles with clang under ARC. Open with Objective-C selected.

XML to C# classes

The XML is converted to a data model first: attributes and child elements become properties, repeated elements become List<T>, and numbers and booleans in the text are typed accordingly. The class is named after the element, so <user id="7"><name>Ada</name></user> gives public class User with public long Id and public string Name, each with a [JsonPropertyName] attribute. Open with XML → C# selected.

XML to Dart classes

Attributes and child elements of your sample XML become typed final fields of a null-safe Dart class named after the element, with fromJson and toJson for the equivalent JSON map. Elements that repeat become List fields. <user id="7"><name>Ada</name></user> produces class User with final int id; and final String name;. Open with XML → Dart selected.

XML to Go structs

The sample XML is turned into Go structs named after its elements; attributes and children become fields with json tags, and an element that occurs more than once becomes a slice. <user id="7"><tag>a</tag><tag>b</tag></user> gives type User struct with Id int64 and Tag []string. Open with XML → Go selected.

XML to Java classes

Attributes and child elements become private fields with getters and setters, repeated elements become List<…> fields, and nested elements become static nested classes, so the whole result compiles as one file. Values are typed as Long, Double, Boolean or String from the sample text: <user id="7"><name>Ada</name></user> produces public class User with private Long id; and private String name;. Open with XML → Java selected.

Inferring a JSON Schema from XML

The XML sample is mapped to JSON (attributes and child elements as properties, repeated elements as arrays) and a JSON Schema 2020-12 document is inferred: integer, number, boolean and string types, nested objects, array item schemas and a required list. <user id="7"><name>Ada</name></user> gives "title": "User" with id as integer and name as string, both required. Open with XML → JSON Schema selected.

XML to Objective-C models

Generates Objective-C header and implementation code for the elements in your XML: one NSObject subclass per element type, typed properties for attributes and children, and dictionary initialisers. For <user id="7"><name>Ada</name></user> you get @interface User : NSObject with NSNumber *id_ (the key "id" is renamed because id is an Objective-C type) and NSString *name. Open with XML → Objective-C selected.

XML to TypeScript interfaces

Your XML sample becomes TypeScript interfaces named after its elements. Attributes and single child elements become properties, and an element that appears more than once becomes an array. <user id="7"><tag>a</tag><tag>b</tag></user> produces export interface User { id: number; tag: string[]; }. Open with XML → TypeScript selected.

YAML to C# classes

The YAML is parsed with js-yaml, so nested mappings, sequences, anchors and flow style all work, and a C# class is generated for every mapping with System.Text.Json attributes. From name: Ada / age: 36 you get public string Name { get; set; } = string.Empty; and public long Age { get; set; }, which is useful for binding configuration files. Open with YAML → C# selected.

YAML to Dart classes

Parses the YAML document and writes null-safe Dart classes with fromJson/toJson, handy for Flutter apps that load YAML configuration as a map. name: Ada / age: 36 produces final String name;, final int age; and a constructor const Root({required this.name, required this.age});. Open with YAML → Dart selected.

YAML to Go structs

Every YAML mapping becomes a Go struct and sequences become slices; fields carry json tags that repeat the original keys (add yaml tags alongside if you decode with gopkg.in/yaml). name: Ada / age: 36 gives Name string `json:"name"` and Age int64 `json:"age"`. Open with YAML → Go selected.

YAML to JavaScript classes

The YAML sample is parsed and each mapping becomes an ES class with a constructor that copies the fields from a loaded object and builds nested class instances. name: Ada / age: 36 gives class Root with this.name = data.name ?? null; and this.age = data.age ?? null;, typed as string and number in JSDoc. Open with YAML → JavaScript selected.

Inferring a JSON Schema from YAML

Because YAML is a superset of JSON's data model, a YAML sample can describe the shape of a document just as well. The tool infers a JSON Schema 2020-12 with types, nested objects, array items and required keys. name: Ada / age: 36 gives "name": {"type": "string"} and "age": {"type": "integer"}, both in required. Open with YAML → JSON Schema selected.

YAML to Objective-C models

Loads the YAML and generates an Objective-C interface and implementation per mapping, with initWithDictionary: for the parsed dictionary. name: Ada / age: 36 gives @property (nonatomic, copy) NSString *name; and @property (nonatomic, strong) NSNumber *age;. Open with YAML → Objective-C selected.

YAML to Python dataclasses

Pair it with PyYAML or ruamel.yaml: load your file, then build typed objects with the generated from_dict(). Each mapping becomes a dataclass with type hints; name: Ada / age: 36 gives name: str and age: int. Open with YAML → Python selected.

YAML to TypeScript interfaces

Describe a YAML configuration or API fixture with TypeScript types: each mapping becomes an exported interface, sequences become arrays and keys missing from some list items are optional. name: Ada / age: 36 produces export interface Root { name: string; age: number; }. Open with YAML → TypeScript selected.

FAQ

What is a POJO?

A Plain Old Java Object: a simple class with private fields and getters and setters, no framework base class. The term is used loosely for any plain data class, which is why this page covers C#, Go, Python and others too.

Does the C# output work with Newtonsoft.Json?

The attributes target System.Text.Json. For Newtonsoft, replace [JsonPropertyName("x")] with [JsonProperty("x")] and the using line; the class shapes are the same.

Is my data uploaded?

No. Parsing and code generation run entirely in your browser. Only the YAML parser library is downloaded from a CDN the first time you choose YAML.

Why is a field typed as object or any?

It was null or an empty array in every place the sample showed it. Put a real value in the sample and generate again.