JSON to Java
Convert JSON into Java entity classes with fields, getters and setters.
Your result will appear here.
JSON to Java online
Generate a Java class skeleton from a JSON sample — typed fields inferred from the values, nested objects as static inner classes — to skip the boilerplate when modelling an API response.
How to use this tool
- Set the class name for the root type.
- Paste a representative JSON object into the input box.
- Click Generate and copy the class into your project, then rename and refine types as needed.
Common uses
Bootstrapping POJOs for a REST client, modelling a config file as a typed class, generating DTOs while exploring an unfamiliar API, and giving students a first draft to correct rather than a blank page.
How it works
The generator infers a Java type per value: whole numbers become int, decimals double, text String, booleans boolean, and arrays List<...> of the element type. A nested object becomes a public static class inside its parent, named from its key. Values the generator cannot pin down — an empty array or a null — fall back to Object, marking the spots your sample does not describe.
Worked example
With class name User and the sample
{ "name": "Ana", "age": 30, "tags": ["a"], "address": { "city": "Berlin" } }the output is a User class with String name, int age, List<String> tags and a nested static Address class holding String city — a skeleton you then annotate for Jackson or Gson.
Privacy and browser processing
Your JSON is processed in your browser with JavaScript — it is never uploaded or stored.
Frequently asked questions
Does it generate getters and setters?
No — the output is the field-and-class skeleton. Add accessors with your IDE's generator, or use it as a record/Lombok starting point; the tedious part (reading the JSON shape) is what gets automated.
Why did a field become Object?
The sample gave nothing to infer from: the value was null, or the array was empty or mixed-type. Feed a fuller sample — one where that array contains a typical element — and the type resolves.
My numbers are IDs. Will int be a problem?
Large IDs can overflow int and must never be treated as quantities anyway. Change ID fields to long or String after generating; the generator infers from value shape, not meaning.
What if different array items have different fields?
Inference follows the elements it sees; inconsistent items can produce a partial or Object-typed field. Generate from the most complete example item, then merge the rest by hand.
Is my JSON uploaded?
No. Generation runs in your browser; nothing leaves the page.