N
NJHTools

JSON to Java Class (POJO)

Paste JSON and get Java classes for every nested object, ready to use with a JSON library such as Jackson. Free, no signup, and generated in your browser so your data stays local.

Language

16 lines · processed in your browser, nothing is uploaded

Java output · Root.java

Generated code appears here.

Example: JSON to Java

This JSON sample, with the root type named User, produces the Java below using the default options.

Input JSON
{
  "id": 1024,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "active": true,
  "score": 98.5,
  "tags": [
    "admin",
    "beta"
  ],
  "address": {
    "city": "London",
    "postcode": "NW1 6XE"
  }
}
Generated Java
// User.java

package com.example;

import java.util.List;

public class User {
    private long id;
    private String name;
    private String email;
    private boolean active;
    private double score;
    private List<String> tags;
    private Address address;

    public long getID() { return id; }
    public void setID(long value) { this.id = value; }

    public String getName() { return name; }
    public void setName(String value) { this.name = value; }

    public String getEmail() { return email; }
    public void setEmail(String value) { this.email = value; }

    public boolean getActive() { return active; }
    public void setActive(boolean value) { this.active = value; }

    public double getScore() { return score; }
    public void setScore(double value) { this.score = value; }

    public List<String> getTags() { return tags; }
    public void setTags(List<String> value) { this.tags = value; }

    public Address getAddress() { return address; }
    public void setAddress(Address value) { this.address = value; }
}

// Address.java

package com.example;

public class Address {
    private String city;
    private String postcode;

    public String getCity() { return city; }
    public void setCity(String value) { this.city = value; }

    public String getPostcode() { return postcode; }
    public void setPostcode(String value) { this.postcode = value; }
}

How to convert JSON to Java

  1. 1Paste a JSON object or array into the input.
  2. 2Select Java as the output language.
  3. 3Name the root class, for example Customer.
  4. 4Adjust options such as the package name if needed.
  5. 5Copy each class into its own .java file.

Getters, setters and Jackson

Jackson maps JSON keys to Java properties through getters and setters or annotated fields. @JsonProperty("original_key") pins the JSON name, so you can follow Java camelCase without breaking deserialization.

Deserialize with new ObjectMapper().readValue(json, Customer.class). If the API may add fields later, configure the mapper or annotate the class with @JsonIgnoreProperties(ignoreUnknown = true) so unknown keys do not throw.

Records and Lombok as alternatives

On Java 16 and later, a record gives you an immutable data class in one line, and recent Jackson versions deserialize records directly. Lombok's @Data or @Value removes getter and setter boilerplate on older codebases.

Whatever style you choose, keep the field types from the generated output: they reflect what was actually in the JSON.

Nulls and boxed types

Primitive fields such as int cannot hold null, so a missing number silently becomes 0. Use boxed types such as Integer or Long for fields that may be absent or null.

JSON numbers without decimals may exceed int range; prefer long for IDs and timestamps.

Frequently Asked Questions

How do I convert JSON to a Java POJO?↓

Paste the JSON, choose Java and copy the generated classes. Each nested object becomes its own class with typed fields.

How do I deserialize the JSON with Jackson?↓

Create an ObjectMapper and call readValue(json, RootClass.class). For lists, use a TypeReference such as new TypeReference<List<Item>>() {}.

How are optional fields detected?↓

Types are inferred from the sample you paste. A field becomes optional only if it is missing from some of the objects, so paste an array with several representative records, or mark the field optional by hand after generating.

Does it handle nested arrays?↓

Yes. Arrays of objects become lists or arrays of a generated class, depending on the output style, and nested arrays are typed element by element.

Is my JSON uploaded to a server?↓

No. The code generator (quicktype) runs entirely in your browser, so the JSON you paste never leaves your device. That makes it safe to use with internal API responses, though you should still strip secrets before sharing generated code.

Last updated: