JSON to Java Class Converter
This JSON to Java converter turns a sample payload into classes. Each object becomes a class with private fields, a Jackson @JsonProperty annotation carrying the original key, and a getter and setter for every field. Boxed types are used rather than primitives, because a primitive cannot represent an absent or null value and JSON regularly has both. Because a .java file may declare several top-level classes but only one public one, the root class is public and the nested ones are package-private — so the whole output compiles as a single file.
How it works
Paste a representative JSON sample and the Java declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.
Each object becomes a class with private fields, a Jackson @JsonProperty annotation carrying the original key, and a getter and setter for each field.
A .java file may hold several top-level classes but only one public one, so the root class is public and the nested ones are package-private — which compiles as-is if you paste the whole thing into one file.
Generation runs entirely in your browser — nothing you paste is uploaded.
How to convert JSON to Java classes
- Paste a representative JSON payload into the input on the left.
- Set a package name if you want one declared.
- Copy the generated classes into your project.
What is generated
Each object becomes a class with private fields, a Jackson @JsonProperty annotation carrying the
original key, and a getter and setter for each field. Boxed types are used rather than primitives, because a
primitive cannot represent an absent or null value and JSON regularly has both.
Why only one class is public
A .java file may declare several top-level classes but only one public one — that is a rule of the
language, tied to the filename. The root class is therefore public and the nested ones are package-private, so the
whole output compiles as a single file. Split them into separate files and you can make each one public.
Give it a representative sample
The types are inferred from the data you paste, so the quality of the output depends on how complete your example is. Two things are worth including: an array with more than one element, so fields that appear in some records but not others get marked optional rather than assumed mandatory; and real values rather than placeholders, so numbers are recognised as numbers and whole numbers are told apart from decimals.
What inference cannot tell you
A sample shows what the data was, not what it can be. A field that happened to be null in every record you pasted has no discoverable type, and an enum looks exactly like a string. Treat the generated classes as a first draft that saves the typing, then tighten the parts you know more about than the sample does.
Frequently asked questions
How do I generate a Java class from JSON?
Paste a representative payload into the left panel, optionally set a package name, and copy the generated classes into your project.
Why are only some classes public?
A .java file may declare several top-level classes but only one public one, since the public class name must match the filename. The root is public and the rest package-private, so the whole output compiles as one file. Split them into separate files to make each public.
Why boxed types instead of int and boolean?
A primitive cannot represent an absent or null value, and JSON has both. Long and Boolean can hold null, so an optional field round-trips honestly instead of silently becoming 0 or false.
Does it work with Gson instead of Jackson?
The class shapes are the same; swap @JsonProperty for @SerializedName and the classes work with Gson.
Is my JSON uploaded anywhere?
No. Generation happens entirely in your browser.
Related tools
JSON to C# Class Converter
This JSON to C# converter generates classes with System.Text.Json attributes and nullable types.
JSON to Go Struct Converter
This JSON to Go converter generates structs with the json tags encoding/json needs.
JSON to TypeScript Converter
This JSON to TypeScript converter turns a sample payload into exported interfaces.