Data to Code Generators

Paste a sample JSON or XML document and get matching types or classes in nine languages, or a JSON Schema. It saves typing out a model by hand and avoids spelling mistakes in field names.

Popular Data to Code Generators

All Data to Code Generators (20)

About Data to Code Generators

The generators infer a type for every field from the values in your sample: strings, integers, decimals, booleans, arrays and nested objects each map to a type in the target language, and every nested object becomes its own named type. Arrays of objects are merged so that fields seen in any element appear in the generated type.

Inference can only see what the sample contains. A field that is null in the sample gets a catch-all type, and an empty array cannot reveal its item type, so review optional and nullable fields before using the code.

Which tool to use

Pick the generator for the language of the code that will read the data. The JSON generators give types whose field types follow the sample; the XML generators give the same structure with every value typed as a string, and attributes as extra fields. Each language page explains what the generated code still needs before it compiles and decodes real data, for example renamed keys, reserved words and nullable fields. Choose JSON to JSON Schema or XML to JSON Schema when you want to validate documents rather than model them in code.

Frequently asked questions

Why is a field typed as any or Object?

The sample value was null or the array was empty, so there was nothing to infer from. Use a sample where that field has a real value.

Why are XML-generated fields all strings?

XML does not record data types, so every value arrives as text. Change the types by hand where you know a field is numeric.

Is the generated code ready for production?

Treat it as a starting point. Review names, nullability, optional fields and any library annotations your project uses.

Common use cases

  • Typing an API response in a TypeScript front end
  • Creating Java or C# DTOs for a new integration
  • Writing Go structs with JSON tags
  • Producing a starting JSON Schema for request validation

Example

export interface Root {
  id: number;
  name: string;
  tags: string[];
}

TypeScript generated from {"id":1,"name":"Ada","tags":["x"]}.