JSON to Java Converter
Java POJOs from a JSON sample, in one compilable file
Input
Output
What does the JSON to Java converter generate?
Mapping a REST response onto Java usually means a stack of POJOs, each with private fields, getters and setters, and somebody has to type them. Give this page one real response and it writes the lot into a single RootObject.java: your package line, only the imports it uses, and a public root class holding each nested object as a public static class. One file means it compiles as generated; the output is checked with javac.
Field names are camelCase. When a key isn't a legal Java name, such as first name, billing_cycle or class, the field is renamed (firstName, billingCycle, class_) and gets a Jackson @JsonProperty("first name") annotation so deserialization still finds the key. Tick Use Lombok to replace the getters and setters with @Data. If you use Gson instead, swap the annotation for @SerializedName.
Number types follow the values: Integer, then Long past 32 bits (a badge serial like 5000000000 lands there), then BigInteger beyond signed 64-bit. Lists are List<T> and lists of lists List<List<T>>; because every element of an array is read, a key that turns up in only one or two objects is still given a field. Wrapper Types is on by default and keeps Integer, Double and Boolean everywhere so any field can be null. Switch it off for int, double and boolean wherever the sample never showed a null. The generator runs in the page, with no server involved.
How to use it
Paste JSON and the class updates as you type.
Paste a JSON sample
Paste JSON on the left or open a saved response with Upload; Sample fills in a nested subscriber record. A staff record is a good test of key renaming and number widths:
{"employeeId":"E-20417","full_name":"Rosalind Kaur","leaveDays":25,"hourlyRate":41.75,"badgeSerial":5000000000,"managerId":null,"skills":["Kafka","Spring Boot"]}Set Class Name and Package (invalid characters are dropped from the package). Not sure the JSON is valid? Try the JSON Validator first.
Check the output
The Output panel shows RootObject with Account, Device and Subscriber nested inside it for the sample. Prefer one class per file? Move each static class out and drop the static keyword.
Copy or download
Copy the code or Download it. Then read it with Jackson: new ObjectMapper().readValue(json, RootObject.class).
Where this saves time
Spring Boot request and response bodies
Paste the payload a client sends you and get the classes for your @RequestBody parameter. Spring Boot uses Jackson by default, so the @JsonProperty renames work without extra setup.
Calling external APIs
Capture a response from the API you integrate with and generate typed classes for RestTemplate, WebClient or a plain HttpClient plus ObjectMapper.
Android models
Generate plain classes for Retrofit with a Jackson converter, or switch the annotation to Gson's @SerializedName if your app uses Gson.
Spotting 64-bit IDs
Order numbers and epoch-millisecond timestamps overflow an int. The converter checks every value, so those fields come out as Long instead of failing at runtime.
Common Questions
Which JSON library does the output target?
The classes are plain Java and work with any library that maps fields or getters. Renamed keys use Jackson's @JsonProperty, so with Jackson they work as generated. With Gson, replace it with @SerializedName.
Why is everything in one file?
Java allows only one public top-level class per file (see the Java Language Specification), so the nested types are public static classes inside the root class. That way the download compiles immediately. You can split them into separate files later.
What does Wrapper Types do?
On: every number and boolean uses a wrapper type (Integer, Double, Boolean), so a missing value is null. Off: fields use primitives unless the sample had a null there or the key was missing from some objects.
How are null values typed?
With only nulls to go on, as with "managerId": null for someone who reports to nobody yet, the field is declared private Object managerId; and you swap Object for the real type later. If another record has a string there, the field is plain String: a Java reference can hold null already, so no extra marker is added.
What happens with a root array?
Its objects become the root class, and the file starts with // The JSON root is an array: read it as List<Employee>. when Class Name is Employee. With Jackson that means passing a TypeReference<List<Employee>> to readValue. A root of plain values, or a lone string, has no fields to declare, so you get a short message in place of a class.
Is my JSON sent to a server?
No. The Java source is assembled by script inside the page you are looking at, and no request carries the JSON anywhere. A handful of records is plenty for inference; input above 256 KB is refused.
Other JSON Tools You Might Need
On Kotlin or Scala instead, or want to check the JSON first?