Skip to content
DevTools

JSON to Code — TypeScript, Java, C#, Python, Go, Rust & More

Generate typed models from JSON in 14 languages: TypeScript, Java, C#, Python, Kotlin, Swift, Go, Rust, Dart, PHP, Ruby, C++, Zod and NestJS DTOs. Free and 100% in your browser.

Input

Output

Ready

Runs locally in your browser — your data is never uploaded.

About the JSON to Code

This JSON to code generator turns a sample JSON document into ready-to-use typed models in 14 languages: TypeScript interfaces, Java POJOs, C# classes, Python dataclasses, Kotlin data classes, Swift Codable structs, Go structs, Rust serde structs, Dart models, PHP 8 classes, Ruby classes, C++ structs, Zod schemas and NestJS DTOs.

Paste an API response, a config file or any JSON object. The generator infers a type for every field, creates a separate definition for each nested object and merges the fields of every item in an array, so optional and nullable fields aren’t missed. Switch languages from the dropdown at any time — your JSON stays where it is.

How to use it

  1. Paste or upload your JSON in the input editor (or click Sample to try it).
  2. Pick the target language. The code is generated as you type.
  3. Set the root name to control the top-level type name, and choose whether nested objects get their own types or become a map/dictionary.
  4. Copy the result or download it as a source file. The page URL remembers the language, so you can bookmark e.g. JSON to Go.

Features

  • 14 target languages from one input
  • Nested objects become separate, reusable types
  • Arrays of objects are merged so optional fields are detected
  • Integers, decimals (even 2.00), booleans and nulls are typed accurately
  • Keys that aren’t valid identifiers are renamed and mapped back to the original JSON key (@JsonProperty, [JsonPropertyName], serde rename, CodingKeys…)

How JSON types map to each language

Languagestringintegerdecimalbooleanarrayobjectnull / missing
TypeScriptstringnumbernumberbooleanT[]interfaceT | null
JavaStringIntegerDoubleBooleanList<T>classnullable wrapper
C#stringintdoubleboolList<T>classint? / double?
PythonstrintfloatboolList[T]@dataclassOptional[T]
KotlinStringIntDoubleBooleanList<T>data classT?
SwiftStringIntDoubleBool[T]struct: CodableT?
Gostringintfloat64bool[]Tstruct*T
RustStringi64f64boolVec<T>structOption<T>
DartStringintdoubleboolList<T>classT?
PHPstringintfloatboolarrayfinal class?T
RubyStringIntegerFloattrue/falseArrayclassnil
C++std::stringint32_tdoubleboolstd::vector<T>structstd::optional<T>
Zodz.string()z.number().int()z.number()z.boolean()z.array()z.object().nullable()
NestJS DTO@IsString()@IsInt()@IsNumber()@IsBoolean()@IsArray()@ValidateNested()@IsOptional()

Language notes

JSON to TypeScript interfaces

Each nested object becomes its own exported interface. Keys that are not valid identifiers are quoted, fields missing from some array items are marked optional with ?, and null values become union types.

Paste the interfaces into a .ts file and annotate your fetch results, e.g. const user: Root = await res.json().

JSON to Java POJO classes

The generator produces plain Java classes with private fields plus getters and setters. Boxed types (Integer, Double, Boolean) are used so JSON nulls map cleanly, and @JsonProperty is added when a JSON key is not a valid camelCase Java name.

Deserialize with Jackson: new ObjectMapper().readValue(json, Root.class). Each class goes in its own file, or make nested classes static.

JSON to C# classes

Properties are PascalCase as .NET conventions expect, and each one carries a [JsonPropertyName] attribute so System.Text.Json maps it back to the original JSON key. Value types that can be null become nullable (int?, bool?).

Deserialize with System.Text.Json: JsonSerializer.Deserialize<Root>(json). For Newtonsoft.Json, replace [JsonPropertyName] with [JsonProperty].

JSON to Python dataclasses

The output uses standard-library dataclasses with type hints. Field names are converted to snake_case, nullable values become Optional, and fields missing from some items get a default of None and are moved after required fields.

Construct instances with Root(**data) for flat objects, or use a library such as dacite or pydantic to build nested dataclasses from dictionaries.

JSON to Kotlin data classes

Each object becomes an immutable data class annotated with @Serializable for kotlinx.serialization. Optional fields default to null, and @SerialName preserves the original JSON key when it is not valid camelCase.

Decode with Json.decodeFromString<Root>(json). With Moshi or Gson, drop the kotlinx annotations and use their equivalents.

JSON to Swift Codable structs

Each object becomes a Codable struct with camelCase properties. When a JSON key differs from the Swift property name, a CodingKeys enum is generated so JSONDecoder maps it correctly. Optional and nullable values become optionals.

Decode with try JSONDecoder().decode(Root.self, from: data).

JSON to Go structs

Each object becomes an exported struct with PascalCase fields and json tags that keep the original key names. Optional fields get omitempty, and nullable values become pointers so you can tell null from the zero value.

Decode with json.Unmarshal(data, &root) using encoding/json.

JSON to Rust serde structs

Structs derive Serialize and Deserialize for serde. Field names are converted to snake_case with #[serde(rename)] to keep the JSON key, and optional or nullable fields become Option<T>.

Add serde (with the derive feature) and serde_json to Cargo.toml, then let root: Root = serde_json::from_str(&json)?;

JSON to Dart model classes

Each class has final fields, a const constructor with required named parameters and a fromJson factory that handles nested objects, lists and doubles that arrive as integers.

Use Root.fromJson(jsonDecode(body)) in Flutter or any Dart app. For larger projects, consider json_serializable with these classes as a starting point.

JSON to PHP classes

The output targets PHP 8 with strict types and constructor property promotion. Nested objects become their own classes, and arrays of objects are documented with a @var docblock for static analysers.

Hydrate with a mapper such as Symfony Serializer or Valinor, or call new Root(...$data) for flat structures.

JSON to Ruby classes

Each object becomes a plain Ruby class with attr_accessor and an initializer that takes the parsed hash. Nested objects and arrays of objects are instantiated as their own classes.

Use Root.new(JSON.parse(body)). In Rails you could swap these for Struct, Data (Ruby 3.2+) or ActiveModel classes.

JSON to C++ structs

Plain structs with standard-library types, using std::optional for nullable values and nlohmann::json for values whose type can't be inferred.

With nlohmann/json, add NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Root, field1, field2, …) after each struct and call json.get<Root>().

JSON to Zod schemas

One Zod schema is generated per object, child schemas first so they can be referenced, and each is paired with an inferred TypeScript type. Missing fields use .optional() and null values use .nullable().

Validate untrusted data with rootSchema.parse(data) or safeParse for error handling — you get runtime validation and static types from one definition.

JSON to NestJS DTO DTO classes

Each object becomes a DTO class with class-validator decorators, plus @Type from class-transformer so nested objects and arrays of objects are validated. Optional or nullable fields get @IsOptional().

Use the DTO as a controller parameter type (@Body() body: RootDto) with the global ValidationPipe enabled and transform: true.

Frequently asked questions

How are field types inferred?

From the values in your sample. Every element of an array is examined, so a field that is a number in one item and null in another becomes a nullable number. Include representative data for the best results.

Interfaces or types — which does it generate?

It generates export interface declarations, which are the most common choice for describing JSON shapes and can be extended or merged later. You can rename them to type aliases if your codebase prefers that style.

Does it work with Jackson and Gson?

Yes. The classes are plain POJOs with getters and setters, which both Jackson and Gson can bind. The @JsonProperty annotations are Jackson-specific; for Gson, swap them for @SerializedName.

System.Text.Json or Newtonsoft.Json?

The output uses System.Text.Json attributes, the default in modern .NET. For Newtonsoft, replace the using statement and change [JsonPropertyName("x")] to [JsonProperty("x")].

Can I get Pydantic models instead?

Change @dataclass to a class that inherits from pydantic.BaseModel — the annotated fields are already compatible, and Pydantic will then validate and coerce nested data for you.

Does it work on Android?

Yes. kotlinx.serialization works on Android and Kotlin Multiplatform; add the serialization Gradle plugin and dependency.

What is AnyCodable?

Swift has no built-in type for arbitrary JSON. Fields whose type cannot be inferred (for example, always null) use AnyCodable — add a small AnyCodable package or change the type once you know it.

Why are some fields pointers?

In Go a missing number is 0 and a missing string is "". When the sample contains null, a pointer lets you distinguish "not set" from a real zero value.

Why i64 and f64?

JSON numbers carry no size information, so the generator uses the widest common types. Narrow them to i32, u32 or f32 if you know the range.

Does it support null safety?

Yes. Fields that can be null or missing are typed with ? and are not marked required in the constructor.

Which PHP version is required?

PHP 8.0+ for constructor property promotion and nullable types. Add readonly to the properties on PHP 8.1+ if the objects should be immutable.

Does it use symbols or string keys?

The initializer reads string keys, which is what JSON.parse returns by default. Use hash.transform_keys(&:to_s) if you parse with symbolize_names: true.

Which JSON library should I use?

The output is library-agnostic structs. nlohmann/json is the most popular choice and can map these structs with one macro per type.

Why use Zod instead of plain TypeScript types?

TypeScript types vanish at runtime. Zod checks real API responses, form input or config files and gives you typed data only if it matches.

Do I need class-transformer?

Yes, for nested validation. ValidationPipe uses class-transformer to turn plain objects into DTO instances so @ValidateNested can inspect them.

Is my data uploaded anywhere?

No. All processing happens in JavaScript inside your browser tab. Your input is never sent to a server, logged or stored, so it is safe to use with internal or sensitive data.