How to convert JSON to Java
- Paste your JSON into the left panel, or click Load Sample.
- Java is already selected as the output on the right.
- Click Convert, then Copy Output.
Example
This JSON:
{ "id": 101, "name": "Ada Lovelace", "email": "ada@example.com", "active": true, "balance": 250.75,
"address": { "city": "London", "postcode": "N1 9GU" }, "tags": ["admin", "beta"] } becomes:
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Address {
private String city;
private String postcode;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RootObject {
private int id;
private String name;
private String email;
private boolean active;
private double balance;
private Address address;
private List<String> tags;
} How JSON types map to Java
| JSON value | Java type |
|---|---|
"text" | String |
101 | int |
250.75 | double |
true | boolean |
{ … } | a new class named after the key |
["a", "b"] | List<String> |
Lombok or plain POJO?
Pick Lombok under Java Options and every class gets @Data plus the constructor annotations you choose (no-args, all-args or both). That keeps classes short, but your project needs the Lombok dependency and annotation processing. Pick Standard (POJO) for classes with private fields, getters and setters and no extra library, for example in plain Java EE or Android code.
Using the classes with Jackson or Gson
Spring Boot and most Java projects read JSON with Jackson. The generated field names match your JSON keys in camelCase, so objectMapper.readValue(json, RootObject.class) works without extra annotations. If your API uses snake_case keys such as user_name, either choose Snake Case output, or keep camelCase fields and set PropertyNamingStrategies.SNAKE_CASE on the ObjectMapper.
Things to check after generating
- Rename
RootObjectto a name that fits your domain. - IDs and counters that can grow past 2,147,483,647 should be
long, and money is safer asBigDecimalthandouble. - A field that is
nullin your sample has no type to go on; give it a real value first. - On Java 16 or later, small immutable DTOs can also be written as
records.
Is my JSON sent anywhere?
Your JSON is sent to our server, converted in memory and returned; it isn't stored. See the privacy policy.
Frequently asked questions
How do I convert JSON to a Java POJO?
Paste the JSON on the left, keep Java selected on the right, choose Lombok or Standard (POJO) and click Convert. Copy the classes into your project and rename RootObject.
Does it create classes for nested JSON objects?
Yes. Each nested object becomes its own class named after its key, and the parent gets a field of that type. Arrays of values become List fields.
Do I need Lombok?
Only if you choose the Lombok option. Standard (POJO) output has getters and setters written out and needs no library.
Can I convert Java back to JSON?
Yes. Choose Java toString() / DTO as the input language to turn log output such as UserDTO(id=1, name=Amit) into JSON.
Other languages: JSON to TypeScript · JSON to Go · JSON to Python · JSON to C# · JSON to Kotlin · all languages