JSON to Java Class Generator

Convert any JSON into Java POJO classes instantly. Get fully structured Java classes with private fields, public getters, setters, and optional Jackson or Gson annotations - free, no account needed.

What are Java POJOs and Why Do They Matter?

A POJO (Plain Old Java Object) is the backbone of data modeling in Java. When you receive JSON from a REST API, a database, or a configuration file, you need a Java class that mirrors that JSON structure so your application can work with it in a type-safe way. Writing these classes by hand is tedious and error-prone, especially for large or deeply nested JSON payloads.

A typical POJO follows a strict convention: private fields that match the JSON keys, a no-argument constructor, and public getter and setter methods for each field. For example, the JSON {"userId": 42, "name": "Alice"} maps to a Java class with private int userId and private String name, along with their corresponding getUserId(), setUserId(), getName(), and setName() methods.

POJOs are used across the entire Java ecosystem: Spring Boot REST controllers, Android network layers, Hibernate entity models, and standalone data processing utilities all rely on POJOs to represent structured data. Automating their creation saves hours of boilerplate work and eliminates typos in field names.

How the JSON to Java Converter Works

Our converter parses your JSON and generates Java source code following standard conventions. Here is how to use it:

  1. Paste or type your JSON in the input panel
  2. Click "Open JSON to Java Converter" above to launch the tool
  3. The generator instantly produces a complete Java class structure
  4. Choose your annotation style: Jackson, Gson, Lombok, or plain POJO
  5. Copy the generated code and paste it into your IDE

The tool infers Java types from JSON value types: JSON strings become String, JSON numbers with decimals become Double, whole numbers become Integer or Long, JSON booleans become Boolean, JSON arrays become List<T>, and nested JSON objects become separate inner classes.

Jackson vs Gson Annotations

Two libraries dominate JSON processing in Java: Jackson and Gson. Understanding which annotations to use depends on which library your project includes.

Jackson is the default in Spring Boot and is the most widely used Java JSON library. Key annotations include:

Gson is popular in Android development and standalone Java projects. Its primary annotation is:

Lombok is not a JSON library but a code generation tool. Adding @Data to your POJO class automatically generates all getters, setters, equals(), hashCode(), and toString() at compile time, dramatically reducing boilerplate.

Common Use Cases for JSON to Java Conversion

Generating Java classes from JSON is a daily task for many backend and Android developers. Here are the most common scenarios where this tool saves significant time:

Frequently Asked Questions

What is a Java POJO and how is it different from a regular class?

A POJO (Plain Old Java Object) is a Java class with no special requirements - no mandatory superclasses, no required interfaces, and no required annotations. It simply has private fields and public getters/setters. The term distinguishes it from objects that require a specific framework, like EJBs (Enterprise JavaBeans). In the context of JSON, POJOs are the standard way to represent JSON data as a Java object that Jackson or Gson can serialize and deserialize.

Which annotations should I add to my generated Java class?

If you use Spring Boot or any Jackson-based project, add @JsonProperty on fields whose JSON key differs from the Java field name, and @JsonIgnoreProperties(ignoreUnknown = true) at the class level to tolerate extra fields. For Android with Retrofit and Gson, use @SerializedName. If your team uses Lombok, replace all getters and setters with @Data on the class to keep the code minimal.

How are nested JSON objects converted to Java?

Each nested JSON object becomes a separate Java class. For example, if your JSON has an "address" field that contains an object with "street", "city", and "zip", the generator creates an Address class with those three fields, and the parent class gets a field private Address address. Deeply nested structures are handled recursively, producing a clean class hierarchy.

How does the tool handle JSON arrays when generating Java classes?

JSON arrays are mapped to List<T> where T is the inferred element type. An array of strings becomes List<String>, an array of numbers becomes List<Integer> or List<Double>, and an array of objects becomes List<YourClassName> where the element class is also generated. The import for java.util.List is automatically included in the output.

Ready to generate your Java classes?

Free, instant, 100% private. No account needed.

JSON to Java POJO Conversion

Java POJOs (Plain Old Java Objects) are the standard way to deserialize JSON in Java. Jackson and Gson are the two most popular libraries, each with slightly different annotations.

JSON Input → Java POJO

// JSON
{"userId": 1, "name": "Alice", "active": true, "score": 98.5}

// Java (Jackson)
import com.fasterxml.jackson.annotation.JsonProperty;

public class User {
    @JsonProperty("userId")
    private int userId;

    @JsonProperty("name")
    private String name;

    @JsonProperty("active")
    private boolean active;

    @JsonProperty("score")
    private double score;

    // Getters and setters
    public int getUserId() { return userId; }
    public void setUserId(int userId) { this.userId = userId; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
}

Library Comparison

LibraryAnnotationDeserialize MethodNotes
Jackson@JsonPropertyObjectMapperMost popular, Spring default
Gson@SerializedNameGson().fromJson()Google library, simpler API
Moshi@JsonMoshi adapterKotlin-friendly, modern
JSON-B (Jakarta)@JsonbPropertyJsonb.fromJson()Java EE standard

Deserializing in Java

// Jackson
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(jsonString, User.class);

// Jackson from file
User user = mapper.readValue(new File("user.json"), User.class);

// Gson
Gson gson = new Gson();
User user = gson.fromJson(jsonString, User.class);

// List of objects
List<User> users = mapper.readValue(jsonArray,
    mapper.getTypeFactory().constructCollectionType(List.class, User.class));

Also useful: JWT Decoder | JSON Validator | JSON Formatter | JSON to Go | JSON to C# | JSON to Kotlin

How to Convert JSON to Java POJO — Step by Step

  1. Paste your JSON into the converter above
  2. Click Convert — the tool analyzes field names and infers Java types
  3. Copy the generated class definitions into your Java project
  4. Add Jackson or Gson dependency to your pom.xml/build.gradle
  5. Use ObjectMapper to deserialize JSON into your POJO
// Generated POJO from {"name": "Alice", "age": 30, "email": "alice@example.com"}
public class User {
    @JsonProperty("name")
    private String name;

    @JsonProperty("age")
    private int age;

    @JsonProperty("email")
    private String email;

    // Getters and setters omitted for brevity
}

// Deserialization with Jackson
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(jsonString, User.class);
System.out.println(user.getName()); // "Alice"

// Deserialization with Gson
Gson gson = new Gson();
User user = gson.fromJson(jsonString, User.class);

Jackson vs Gson: Which to Use?

Feature Jackson Gson
Maintained byFasterXMLGoogle
Spring Boot defaultYesNo
Annotation style@JsonProperty, @JsonIgnore@SerializedName, @Expose
Streaming APIYes (JsonParser)Yes (JsonReader)
PerformanceFaster for large objectsFaster for small objects
ConfigurationObjectMapper (reusable)GsonBuilder
Best forSpring projects, enterpriseAndroid, simple projects

JSON Type Mapping: JSON to Java

JSON Type Java Type Notes
StringStringStandard Java string
Integerint / IntegerUse Integer for nullable fields
Float/Doubledouble / DoubleUse Double for nullable
Booleanboolean / BooleanUse Boolean for nullable
nullnullObject types only, not primitives
ArrayList<T> / T[]T is the element type
ObjectCustom classEach object becomes a Java class

JSON to Java POJO Generator vs Alternatives

Several tools generate Java classes from JSON. Here is how this tool compares to the most common alternatives developers use:

Tool Free Annotations Nested Objects No Signup
JSON Web ToolsJackson & Gson
json2csharp.comC# only
jsonschema2pojo.orgJackson, Gson, JSR
IntelliJ IDEA pluginPaid IDERequires IDE

How to Convert JSON to Java POJO Online — Step by Step

Converting JSON to a Java POJO (Plain Old Java Object) online takes under 30 seconds:

  1. Paste your JSON into the input field above
  2. Choose your annotation style: None, Jackson (@JsonProperty), or Gson (@SerializedName)
  3. Set the root class name (e.g. User, Product)
  4. Click Convert — inner nested objects become separate inner classes automatically
  5. Copy the generated Java code into your IDE

Complete JSON to Java POJO Example

Input JSON:

{
  "userId": 101,
  "name": "Alice Smith",
  "email": "alice@example.com",
  "active": true,
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "zip": "10001"
  },
  "tags": ["admin", "editor"]
}

Generated Java POJO (with Jackson annotations):

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

public class User {
    @JsonProperty("userId")
    private int userId;

    @JsonProperty("name")
    private String name;

    @JsonProperty("email")
    private String email;

    @JsonProperty("active")
    private boolean active;

    @JsonProperty("address")
    private Address address;

    @JsonProperty("tags")
    private List<String> tags;

    // Getters and setters...

    public static class Address {
        @JsonProperty("street")
        private String street;

        @JsonProperty("city")
        private String city;

        @JsonProperty("zip")
        private String zip;
        // Getters and setters...
    }
}

Also useful: JSON to TypeScript | JSON to Go struct | JSON to C# | JSON to Python dataclass | JSON Schema Validator