JSON to Java Class Generator – POJO & Records

Paste JSON and get Java classes (POJOs with getters and setters) or Java records, with nested classes, lists and Jackson annotations.

JSON Input

Ln 1, Col 1Empty

Java

Your result will appear here.
No result yet

What Is a JSON to Java Converter?

A JSON to Java converter reads example JSON and writes matching Java classes, so you can map API responses to objects with Jackson, Gson or Spring without typing every field by hand.

How to Generate Java Classes from JSON

  1. Paste a sample of your JSON, or drop a .json file on the box.
  2. Choose classes with getters and setters, or Java records.
  3. Click Generate Java, or press Ctrl + Enter.
  4. Copy the code or download the .java file.

Features

  • Nested objects become their own classes, arrays become List<...>.
  • snake_case keys become camelCase fields, with @JsonProperty to keep the JSON name.
  • Optional and null values use boxed types like Long and Boolean.
  • Java records for modern, immutable data classes.
  • Runs in your browser. Your JSON is never uploaded.

Example

JSON
{
  "user_id": 42,
  "firstName": "Emily",
  "email": "emily@example.com",
  "tags": ["admin"],
  "address": { "city": "London" },
  "manager": null
}
Java (record, with Jackson)
public record User(
    @JsonProperty("user_id") long userId,
    String firstName,
    String email,
    List<String> tags,
    Address address,
    Object manager
) {}

record Address(
    String city
) {}

user_id becomes the Java-style userId, and @JsonProperty tells Jackson which JSON key to read. Numbers without decimals become long so large IDs never overflow, and manager is Object because the sample only contains null. Change it to the real type if you know it.

Reading JSON with Jackson

Java
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(jsonText, User.class);
System.out.println(user.firstName());

Jackson supports records from version 2.12. If your JSON may contain fields that are not in the class, add @JsonIgnoreProperties(ignoreUnknown = true) to the class, or configure the mapper with FAIL_ON_UNKNOWN_PROPERTIES turned off.

Records or Classes?

  • Records (Java 16+) are short and immutable: perfect for API responses you only read.
  • Classes with getters and setters work on older Java versions and with frameworks that need to change fields after creating the object.

Building an Android or Flutter app? JSON to Kotlin writes Kotlin data classes, and JSON to Dart writes Flutter models.

Frequently Asked Questions

Which libraries does the code work with?

The classes are plain Java and work with Jackson, Gson and Spring. The optional @JsonProperty annotations are from Jackson.

Should I use classes or records?

Records (Java 16+) are short and immutable, which is ideal for API data. Classes with getters and setters work with older Java versions and frameworks that need setters.

Why are some types Long or Boolean instead of long or boolean?

Boxed types are used when a value can be missing or null, because primitive types like long cannot hold null.

Is my JSON uploaded?

No. The code is generated in your browser.

Related Tools