JSON to Java, C#, PHP, TypeScript, Python & Go Code Generator

Paste a JSON payload and instantly generate Java, C# and PHP classes, TypeScript interfaces, Python dataclasses, or Go structs — no server, no uploads.

Sample JSON

Generated Code

How do I generate Java, C# and PHP classes from JSON?

Paste your JSON into the left editor, click Generate, then open the Java, C# or PHP tab. The tool reads the shape of your data and writes matching classes: nested objects become their own classes, arrays become lists, and missing or null values become optional or nullable types. Everything runs in your browser, so nothing is uploaded.

This free online tool turns a sample JSON payload — an API response, a webhook body, a config file — into ready-to-use typed code in six languages: Java, C#, PHP 8, TypeScript, Python and Go. Each language tab shows the same structure, including nested objects, arrays and optional fields, written in that language's own style.

How It Works

  • Paste your JSON into the left editor, or click Sample to try an example payload.
  • Click Generate to analyze the structure — nested objects become named types, arrays are inspected element by element.
  • Switch language tabs to see the same structure as a Java, C# or PHP class, a TypeScript interface, a Python dataclass, or a Go struct.
  • Copy or download the generated code directly into your project.

Why Generate Types Instead of Writing Them by Hand?

Hand-typing classes for a deeply nested API response is slow and error-prone — a single typo in a field name silently breaks type safety. This tool infers field types (string, number, boolean, nested object, array), detects fields that are missing or null in some sample records and marks them optional or nullable, and generates consistent naming for nested types automatically. If you need a validation schema rather than language types, the JSON Schema Generator produces one from the same sample JSON.

Privacy

All analysis happens entirely in your browser using JavaScript. Your JSON is never uploaded to a server, which makes this safe to use with real API responses and internal payloads.

What does the Java, C# and PHP output look like?

Java gets plain classes with private fields and getters and setters, C# gets classes with public properties and nullable reference types, and PHP 8 gets classes with typed constructor-promoted properties. In every language, nested objects become separate classes that are written before the classes that use them.

All three examples below were generated from this one input, using the tool's own code:

{
  "id": 7,
  "first-name": "Ada",
  "class": "admin",
  "score": 9.5,
  "address": {
    "city": "London",
    "zip": null
  },
  "orders": [
    {
      "sku": "A1"
    },
    {
      "sku": "A2",
      "note": "gift"
    }
  ]
}

Java: plain classes with Jackson annotations

Each class has private fields plus a getter and setter for every field. A key that is not a valid Java name, such as first-name or class, gets a safe field name and a @JsonProperty annotation holding the original key. That annotation needs import com.fasterxml.jackson.annotation.JsonProperty;, which the output adds only when it is used. Whole numbers become long, decimals become double, and fields that are optional or null use boxed types such as Long.

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

class Address {
    private String city;
    private Object zip;

    public String getCity() { return city; }
    public void setCity(String city) { this.city = city; }

    public Object getZip() { return zip; }
    public void setZip(Object zip) { this.zip = zip; }
}

class Order {
    private String sku;
    private String note;

    public String getSku() { return sku; }
    public void setSku(String sku) { this.sku = sku; }

    public String getNote() { return note; }
    public void setNote(String note) { this.note = note; }
}

class Root {
    private long id;
    @JsonProperty("first-name")
    private String firstName;
    @JsonProperty("class")
    private String class_;
    private double score;
    private Address address;
    private List<Order> orders;

    public long getId() { return id; }
    public void setId(long id) { this.id = id; }

    public String getFirstName() { return firstName; }
    public void setFirstName(String firstName) { this.firstName = firstName; }

    public String getClass_() { return class_; }
    public void setClass_(String class_) { this.class_ = class_; }

    public double getScore() { return score; }
    public void setScore(double score) { this.score = score; }

    public Address getAddress() { return address; }
    public void setAddress(Address address) { this.address = address; }

    public List<Order> getOrders() { return orders; }
    public void setOrders(List<Order> orders) { this.orders = orders; }
}

C#: classes with System.Text.Json attributes

Properties are PascalCase with { get; set; }, and the file starts with #nullable enable. Every property carries [JsonPropertyName] with the original key, because System.Text.Json matches names case-sensitively by default. Optional or null values become nullable types such as string? and long?; required strings, lists and objects get a default initializer so the compiler does not warn about uninitialized properties.

#nullable enable

using System.Collections.Generic;
using System.Text.Json.Serialization;

public class Address
{
    [JsonPropertyName("city")]
    public string City { get; set; } = string.Empty;
    [JsonPropertyName("zip")]
    public object? Zip { get; set; }
}

public class Order
{
    [JsonPropertyName("sku")]
    public string Sku { get; set; } = string.Empty;
    [JsonPropertyName("note")]
    public string? Note { get; set; }
}

public class Root
{
    [JsonPropertyName("id")]
    public long Id { get; set; }
    [JsonPropertyName("first-name")]
    public string FirstName { get; set; } = string.Empty;
    [JsonPropertyName("class")]
    public string Class { get; set; } = string.Empty;
    [JsonPropertyName("score")]
    public double Score { get; set; }
    [JsonPropertyName("address")]
    public Address Address { get; set; } = new();
    [JsonPropertyName("orders")]
    public List<Order> Orders { get; set; } = new();
}

PHP 8: constructor-promoted classes

Each class is a typed constructor with promoted public properties, under declare(strict_types=1). Nullable values use ?string, and fields missing from some records default to null and are listed after the required ones, as PHP expects. PHP has no built-in mapping attribute, so a renamed key is noted in a comment, and array fields get a @param docblock that describes the item type.

<?php

declare(strict_types=1);

class Address
{
    public function __construct(
        public string $city,
        public mixed $zip,
    ) {
    }
}

class Order
{
    public function __construct(
        public string $sku,
        public ?string $note = null,
    ) {
    }
}

class Root
{
    /**
     * @param Order[] $orders
     */
    public function __construct(
        public int $id,
        public string $firstName, // JSON key: "first-name"
        public string $class,
        public float $score,
        public Address $address,
        public array $orders,
    ) {
    }
}

How are big numbers, nulls and awkward keys handled?

Whole numbers outside the 64-bit range become BigInteger in Java, decimal in C# (string above about 7.9e28) and string in PHP. Other whole numbers become long or int, and decimals become double or float. Invalid keys are renamed, reserved words get a safe name, and mixed arrays fall back to Object, object? or mixed.

Gotchas to know about

  • Big integers lose their digits. The browser rounds any number beyond 253 while parsing JSON, so the tool can see that a value does not fit in 64 bits but cannot recover its exact digits. C# decimal holds whole numbers up to about 7.9×1028; anything larger is typed string with a one-line comment, because reading a JSON number into a string needs a custom converter (or use JsonElement). In PHP, decode such values with JSON_BIGINT_AS_STRING to match the string type.
  • 1.0 is an integer. JSON parsing reads 1.0 as 1, so the field is long or int unless another value in the same array has a fraction. Mixed whole numbers and decimals become double or float.
  • Empty arrays hide the item type. A field that is [] in one record and filled in another becomes a list of Object, object? or mixed. Use records that all contain items to get a typed list.
  • Same name, different shape. Nested objects that share a key name but differ in fields or types get numbered classes, such as Info and Info2; identical shapes share one class. PHP class names are case-insensitive, so names that differ only in case are numbered too.
  • Reserved words. In Java, a key such as class becomes class_ with its original key kept in the @JsonProperty annotation. PHP allows keyword names for properties, so $class and $list stay as written and only $this is renamed. C# property names are PascalCase, so they never collide with keywords. A type name that would clash with the language or the generated imports, like List in Java or Match in PHP, becomes ListType or MatchType.
  • Empty keys. In Java, @JsonProperty("") means "use the default name", so a field for an empty-string key cannot be mapped by annotation and is marked with a comment instead.
  • Deep nesting and size. JSON nested more than 1,000 levels deep is refused with a message. If the estimated output would exceed about 20 MB, such as one object with 185,000 keys, that tab shows "Output too large to display, reduce the input" instead of building it.

What do the TypeScript, Python and Go outputs look like?

TypeScript gets interface declarations, Python gets dataclasses with typing hints, and Go gets structs with json tags. Nested objects become their own named types, fields missing from some records become optional, and null values become nullable types. Switch tabs to compare the same data in all six languages.

TypeScript Interfaces

Nested objects become named interface declarations. Arrays become Type[]. Fields that are missing in some sample records become optional (field?: string); fields that were null become nullable (string | null).

Python Dataclasses

Generates @dataclass classes with type hints from typing (Optional, List, Any). Nested classes are declared before the classes that use them, so the output runs as-is.

Go Structs

Field names are converted to exported PascalCase Go identifiers with matching json:"..." tags so encoding/json unmarshals correctly. Nullable fields use pointer types.

Handles Real-World Payloads

Works with deeply nested objects, arrays of objects with inconsistent fields, mixed number types, and null values — the common shape of real API responses, not just toy examples.

Who Uses This Tool?

Frontend Developers

Generate TypeScript interfaces directly from a real API response so your React, Vue, or Angular components are type-safe from day one — no guessing at the shape of the data.

Backend & Data Engineers

Turn sample JSON payloads (webhooks, third-party API responses, log events) into Python dataclasses, Java classes, C# classes, or PHP 8 classes for validation, serialization, or documentation.

Go Developers

Skip manually writing struct definitions and json tags for every new API integration — paste the response body and get a working struct instantly.

API Consumers

Working against a third-party API with no published SDK or types? Paste an example response and generate a starting point in your language of choice.

Frequently Asked Questions

How does this tool decide if a field is optional or nullable?

If your JSON is an array of objects and a key is missing from some of the objects, the generated field is marked optional. If a key's value is null in at least one sample, the field is generated as nullable (e.g. string | null in TypeScript, Optional[str] in Python, a boxed Long in Java, long? in C#, ?int in PHP). For a single object with no array of examples, every present key is treated as required.

Does it support deeply nested JSON?

Yes. Nested objects at any depth up to 1,000 levels become their own named type (interface, dataclass, struct, or class), named after the parent key. Arrays of nested objects are analyzed element by element and merged into a single type.

What happens with inconsistent data, like an array where some items have extra fields?

The tool merges the shape of every item in the array. Fields present in some items but not others become optional. If the same field has different primitive types across items (e.g. sometimes a number, sometimes a string), it falls back to any / Any / interface{} / Object / object? / mixed for that field.

Is my JSON data uploaded anywhere?

No. All parsing and code generation happens locally in your browser with JavaScript. Nothing is sent to a server, which makes this safe to use with real, sensitive API responses.

Can I generate a JSON Schema instead of code?

Yes — use the dedicated JSON Schema Generator to produce a JSON Schema document (Draft 2020-12 or Draft-07) from the same kind of sample payload.

How are very large integers handled in Java, C# and PHP?

Whole numbers outside the signed 64-bit range become BigInteger in Java, decimal in C# and string in PHP; in C#, values above about 7.9×10^28 do not fit decimal and become string. Other whole numbers become long, long and int, and numbers with a fraction become double, double and float. Browsers round numbers beyond 2^53 while parsing JSON, so the tool can tell a number is too large but cannot recover its exact digits.

Do I need a library to use the generated Java, C# and PHP code?

Only Java needs one, and only for renamed keys: the @JsonProperty annotation comes from Jackson (com.fasterxml.jackson.annotation). C# uses System.Text.Json, which is built into modern .NET. The PHP classes are plain PHP 8 code with no dependencies; you build the objects yourself from json_decode output.

Built by Deepak Kumar — a developer who wanted a JSON tool that respects your privacy. All processing happens in your browser. Your data never leaves your device.