Skip to content
XUtilHub

JSON to Java Class (POJO) Generator

Generate Java classes (POJOs) from JSON, with typed fields, nested classes, getters and setters. Free online converter.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Output

About the JSON to Java

Generate Java POJO classes from a JSON sample. Field types are inferred, nested objects become their own classes, and arrays become List<T>.

Key features

  • Generates Java POJO classes from a JSON sample
  • Infers String, int, long, double, boolean and List<T>
  • Nested objects become their own classes
  • camelCase field names with @JsonProperty when the JSON key differs
  • Optional getters and setters
  • Custom root class name

Generate Java classes from JSON

Writing model classes by hand for every API response is slow and error-prone. Paste a JSON sample and this tool generates Java POJOs with typed fields, nested classes, and optional getters and setters, ready to use with Jackson's ObjectMapper or Spring's RestTemplate / WebClient.

Example

{
  "id": 1024,
  "full_name": "Ada Lovelace",
  "active": true,
  "address": { "city": "London" },
  "roles": ["admin"]
}

generates (getters and setters shortened):

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

public class Root {
    private int id;
    @JsonProperty("full_name")
    private String fullName;
    private boolean active;
    private Address address;
    private List<String> roles;
    // getters and setters…
}

public class Address {
    private String city;
    // getters and setters…
}

Type mapping

JSON valueJava type
"text"String
42int
9007199254740993long
3.14double
trueboolean
[...]List<T>
{...}Generated class
nullObject (refine manually)

Using the classes

ObjectMapper mapper = new ObjectMapper();
Root root = mapper.readValue(json, Root.class);

In Spring Boot, return or accept the class directly in a @RestController method and Jackson handles the conversion.

Tips for better results

  • Use a complete sample. Include every field, and give real values instead of null.
  • Arrays of objects. Include at least one element so its class can be generated.
  • Dates. JSON dates are strings; change the type to LocalDate/Instant and register the Jackson JavaTimeModule.
  • Money. Consider BigDecimal instead of double for prices.

Need a schema for gRPC? Use JSON to Protobuf. Working in PHP? Use JSON to PHP Array. To inspect types first, try JSON Deserialize.

How to use the JSON to Java

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The Java appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Which JSON library are the classes for?

The classes are plain Java and work with Jackson out of the box. @JsonProperty annotations are added only when a JSON key isn't a valid camelCase Java name. Gson users can switch them to @SerializedName.

How are types inferred?

From the sample values: whole numbers become int (or long if too large), decimals become double, true/false becomes boolean, arrays become List<T> and null becomes Object.

Why is a field typed as Object?

Its value in your sample was null, so the type couldn't be inferred. Provide a sample with a real value, or change the type manually.

Can it generate records or Lombok classes?

It generates classic POJOs. To use records, convert each class to record Name(Type field, ...); to use Lombok, delete the getters and setters and add @Data.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools