JSON to Java Converter Online
Turn a JSON sample into Java classes with inferred field types, nested static classes, a package line, and optional Lombok @Data or Jackson @JsonProperty annotations.
How to Generate Java Classes
Paste a JSON example, name the root class and optional package, tick the annotations your project uses, and the generated Java source appears beside your input.
Passo 1
Paste a Sample
Use a real API response rather than a trimmed one, so optional fields show up.
Passo 2
Name the Class
Set the root class name and package, then choose Lombok or Jackson annotations.
Passo 3
Copy the Source
Copy the generated classes into your project or download them as a .java file.
Generate Java POJOs From a Real Payload Instead of Typing Fields by Hand
Every Java service that talks to a JSON API needs a model layer, and that layer is almost always written by hand from a sample response. Field names, types, nested classes and imports are copied one line at a time, and the first real payload from production usually reveals two fields nobody noticed and one that is sometimes a number and sometimes a string. A generator collapses that hour into a paste, and it does the tedious part consistently.
Types are inferred across the whole sample rather than from the first row. Whole numbers that fit a 32-bit range become Integer, larger ones become Long, anything with a decimal point becomes Double, and booleans become Boolean rather than the primitive, because a JSON field can legitimately be absent and a primitive would throw during deserialization. Strings stay String, arrays become a List of the inferred element type, and every distinct object shape gets its own nested static class named after its key.
Naming follows Java convention. camelCase keys pass straight through, snake_case and kebab-case keys are converted to camelCase fields, class names are capitalised and singularised where an array implies a repeated entity, and a key that collides with a reserved word is renamed rather than emitted as code that will not compile. Annotations are opt-in: Lombok @Data replaces the getter and setter boilerplate, and Jackson @JsonProperty pins each field to its original wire name.
The package line is optional and stays out of the file when the field is empty, which keeps small snippets clean. A class count is reported so you can see how many types a payload produced before you paste anything into your project, and the output is plain readable source rather than a compressed blob, so you can adjust naming or nullability in place without fighting a formatter.
Nothing is uploaded. The conversion is a recursive walk over parsed JSON performed in your browser, which matters when the sample contains real customer records, internal hostnames or token shapes that should not leave a laptop. Copy the result, download a .java file, or clear the panel and start again with a different endpoint response. What you get is a first draft that compiles far more often than a hand-typed model does.
Type Inference
Integer, Long, Double, Boolean, String and List types inferred across every row of the sample.
Classi annidate
Each distinct object shape becomes its own static class, named after the key that produced it.
Lombok @Data
Replace getters and setters with one annotation when your project already depends on Lombok.
Jackson Names
JsonProperty annotations keep camelCase fields mapped to the original snake_case wire keys.
Optional Package
Add a package declaration such as com.example.model, or leave the field blank for a clean snippet.
Class Count
See how many types the payload generated before you copy anything into your source tree.
FAQ
Domande frequenti
Whole numbers inside the 32-bit range become Integer, larger ones Long, decimals Double, booleans Boolean, text String, arrays a List of the inferred element type, and nested objects a generated class of their own.
Because a JSON field can be missing or null, and a primitive int or boolean cannot hold either. Boxed types deserialize safely whether the value is present, absent or explicitly null, so the first incomplete record does not throw.
Yes. Tick Lombok @Data and each class is annotated instead of carrying generated getters and setters, which keeps the file short. Leave it off if your project prefers explicit accessors or the annotation is not on the classpath.
They are a checkbox, not a default. Turn them on when your field names differ from the wire names, typically after snake_case keys become camelCase fields, and @JsonProperty keeps that mapping exact without a global naming strategy.
A nested object becomes a static nested class named after its key, and an array of objects becomes a List of that class. Arrays of scalars become a List of String, Integer or Double depending on what the elements actually are.
A key such as class or public cannot be a Java field name, so it is renamed to something legal rather than emitted as broken source. Check that one field when you paste the result, and adjust the name to your team convention.
Yes, type it into the package field and the declaration is added at the top. Leave the field empty and no package line is written at all, which is usually what you want for a snippet pasted into an existing file.
It is a strong first draft. Review naming, nullability and any type you know better than the sample suggests, then paste it in. JSON cannot express unions or every optional nuance, so a compile is the real test.
No. Parsing and generation both happen locally in the page, with no upload step and no server call, so a payload containing real user data or internal identifiers can be converted without leaving your machine.
