JSON to Java Class (POJO)

Convert JSON to Java classes: a POJO with getters and setters, Lombok @Data or a record, with Gson or Jackson names. Free, runs in your browser.

Runs in your browser. Your data never leaves your device.

How to use the JSON to Java Class (POJO)

  1. Paste a sample JSON response.
  2. Choose the style (POJO, Lombok or record) and the annotations (Gson, Jackson or none).
  3. Set the class name and tick nested static classes or boxed types if you need them.
  4. Copy the code into your project.

About this tool

Paste a JSON sample and get Java classes for Android or Spring. Choose a classic POJO with private fields, getters and setters, a Lombok @Data class, or a Java record (Java 16 and later). Keys that are not valid Java names keep their JSON name through Gson's @SerializedName or Jackson's @JsonProperty, nested objects become their own classes or nested static classes, and boxed types such as Integer let missing values stay null.

What is a POJO?

A POJO (plain old Java object) is a simple class with fields, getters and setters and no framework base class. Gson and Jackson fill a POJO from JSON by matching names, so a JSON to POJO converter saves you typing every field. A sample and the kind of class it becomes:

// JSON
{"id": 7, "user_name": "sara", "tags": ["admin"]}

// Java
public class User {
    private int id;
    @SerializedName("user_name")
    private String userName;
    private List<String> tags;

    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    // ... the other getters and setters
}

Reading JSON in Java

Jackson (the default in Spring Boot) uses ObjectMapper and Gson (common on Android) uses fromJson. Both turn JSON text into your class and back.

// Jackson
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(json, User.class);
String back = mapper.writeValueAsString(user);

// Gson
Gson gson = new Gson();
User user2 = gson.fromJson(json, User.class);
String back2 = gson.toJson(user2);

A JSON object or a class?

org.json's JSONObject and Jackson's JsonNode read values by key without a class, which is fine for a quick script. For code you keep, a class is better: the compiler checks names and types, and your IDE can complete them.

IntelliJ plugins and JSON Schema

IntelliJ IDEA and Android Studio have plugins that generate POJOs from JSON; search the plugin marketplace for JSON to POJO. If your API publishes a JSON Schema instead of examples, jsonschema2pojo generates Java classes from the schema and also runs from Maven or Gradle. This tool works from a JSON sample, which is what most APIs document.

JavaScript and messy JSON

JavaScript needs no classes: JSON.parse gives you a normal object, and the JSON to TypeScript tool below adds types. If your JSON is on one long line, beautify it with the JSON formatter first so you can read it and spot mistakes.

GuideHow to Create a Chat App in Android Studio

Frequently asked questions

Can I generate a Java class from JSON online?

Yes. Paste the JSON above, choose POJO, Lombok or record, and copy the classes. Nothing is installed and nothing is uploaded.

POJO, Lombok or record?

A record for read-only data on Java 16 or later; Jackson 2.12+ and Gson 2.10+ support records. Lombok @Data if the project already uses Lombok. A plain POJO works everywhere, including older Android code.

Gson or Jackson?

Jackson for Spring and server code, Gson for Android projects that already use it. Pick the one your project has, so you don't add a second JSON library.

Is my JSON sent anywhere?

No. The classes are made in your browser.

More json tools

JSON and code models

All 31 free tools →
JSON tool · Runs in your browser

JSON Formatter

Format JSON online: beautify messy JSON with 2 or 4 spaces or tabs, sort keys, minify it to one line and find errors. Free, runs in your browser.

Free · No sign-upOpen tool
JSON tool · Runs in your browser

JSON Validator

Check if JSON is valid and see the exact line and column of any error, with a hint on how to fix it. A free online JSON validator in your browser.

Free · No sign-upOpen tool
JSON tool · Runs in your browser

JSON to Kotlin Data Class

Paste JSON and get Kotlin data classes for Android, with kotlinx.serialization, Gson or Moshi names, nullable fields and defaults. Free, in your browser.

Free · No sign-upOpen tool
JSON tool · Runs in your browser

JSON to Dart (Flutter)

Convert JSON to null-safe Dart model classes for Flutter, with fromJson, toJson and an optional copyWith. Free, no sign-up, runs in your browser.

Free · No sign-upOpen tool