JSON → Java

Class:
JSON Input
Loading editor…
Java Classes
Loading editor…

JSON to Java

Paste any JSON and get Java classes instantly. Nested objects become separate classes, arrays of objects are typed as List<T>, and you can add Jackson or Gson annotations, or generate Lombok-based classes instead of manual getters and setters.

Nested classes
Deep objects become separate named classes.
Annotations
Optional Jackson @JsonProperty or Gson @SerializedName.
Lombok
Swap manual getters/setters for @Data.
Client-side
No data is uploaded. Everything runs in your browser.

How JSON Structures Map to Classes

Every JSON object becomes a Java class. Nested objects generate additional classes named after the key. Arrays of objects generate a class for the element type, with the key name singularized and turned into List<T>.

Input JSON:

{
  "id": 1,
  "name": "Alice",
  "address": { "city": "Springfield", "zip_code": "12345" },
  "posts": [
    { "id": 101, "title": "Hello World" }
  ]
}

Generated Java:

import java.util.List;

public class Root {
    private int id;

    private String name;

    private Address address;

    private List<Post> posts;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    // ...remaining getters and setters
}

class Address {
    private String city;

    private String zipCode;

    // ...getters and setters
}

class Post {
    private int id;

    private String title;

    // ...getters and setters
}

Only the root class is declared public, since a single Java file can have at most one public top-level class — the rest are package-private, so the whole file compiles as-is if you save it as Root.java.

Field Naming and Type Inference

JSON keys are converted to idiomatic Java camelCase field names — zip_code becomes zipCode, user-id becomes userId. If a key collides with a Java reserved word (like class or default), an underscore is appended.

Numbers are typed based on their value: whole numbers that fit in a 32-bit range become int, larger whole numbers become long, and any decimal value becomes double. Strings become String, booleans become boolean, and null or missing fields use the boxed wrapper type (Integer, Boolean, etc.) instead of the primitive, since primitives can't hold null.

When an array of objects has inconsistent shapes, or a field's type varies across array elements, the tool falls back to Object rather than guessing incorrectly.

Annotations and Lombok

By default, fields keep their idiomatic camelCase names with no annotations — you'll need to handle the original JSON key names yourself if they differ.

Switch to Jackson to add @JsonProperty("original_key") above every field, or Gson to add @SerializedName("original_key") instead — both map the Java field back to its original JSON key so serialization round-trips correctly regardless of naming differences.

Toggle Lombok to replace the manually generated getters and setters with a single @Data annotation from the Lombok library, producing a much shorter class. This requires the lombok dependency on your classpath to compile.

Frequently Asked Questions

Why is only one class marked public?

Java only allows one public top-level class per file, and it must match the filename. The generator marks the root class public and leaves nested classes package-private, so the whole output compiles as one file (e.g. Root.java) without modification.

Why do some fields use Integer instead of int?

A field that is sometimes null or missing across your JSON sample is generated with the boxed wrapper type (Integer, Long, Double, Boolean) instead of the primitive, since Java primitives cannot represent null.

What's the difference between Jackson and Gson annotations?

Both map a Java field back to its original JSON key name. Jackson uses @JsonProperty("key") from com.fasterxml.jackson.annotation, while Gson uses @SerializedName("key") from com.google.gson.annotations. Pick whichever JSON library your project already uses.

What does the Lombok option change?

With Lombok enabled, each class gets a single @Data annotation instead of manually written getters and setters, significantly shortening the output. Your project needs the Lombok dependency and annotation processor configured to compile it.

How are duplicate nested object names handled?

If two different parts of the JSON produce the same class name (e.g. both user.address and company.address become Address), the first one encountered wins and is reused. Rename the conflicting class manually after generating if the shapes differ.

Is my JSON uploaded anywhere?

No. The entire conversion runs in your browser with no network requests. Nothing is transmitted.

More Tools