JSON to Java Class Generator
Convert a JSON sample into Java records with typed fields, nested types and List generics. Handles nulls, arrays and deep nesting. Browser-only.
Input JSON
How it works
- Paste a JSON sample on the left and click Generate Java.
- Every nested object becomes a typed
record(orclass); arrays becomeList<Type>. - Switch the style selector to emit classic POJO classes with getters and setters instead of records.
- Nothing is uploaded — the conversion runs in your browser.
Type mapping
| JSON value | Java type |
|---|---|
42 | int (or long if large) |
3.14 | double |
"hi" | String |
true | boolean |
null | Object |
[1, 2, 3] | List<Integer> |
[{...}] | List<Nested> |
About JSON to Java
Turning a JSON payload into Java types by hand is mechanical and error-prone, especially with nested objects and arrays of objects. This generator reads a sample and emits records or POJOs you can paste into a model package. It infers types from the values it sees, so a sample that covers the real shape of your data produces a more accurate class.
Remember that inference reflects only the sample: a field missing from the sample is missing from the output, and a heterogeneous array becomes List<Object>. Use it as a skeleton, then annotate with @JsonProperty, validation, and serialisation hints for your stack.
How the types are inferred
Integers are emitted as `int`, widening to `long` only when the magnitude exceeds a 32-bit `int` (2,147,483,647) — so a large database id stays `long` automatically. Fractional numbers become `double`, booleans become `boolean`, and strings become `String`.
A JSON array becomes `List<Type>`, using `java.util.List`, and the element type is the union of everything the array contains: objects are merged into one record, primitives are collapsed to their common type, and a mixture falls back to `List<Object>`. An empty array becomes `List<Object>` because no element reveals the intended type.
Records, nesting and naming
Each nested object becomes its own `record` declared before the type that references it, named after the field key with the first letter capitalised. Two keys that capitalise alike collide, so a numeric suffix is appended instead of emitting a duplicate identifier.
Keys that are not legal Java identifiers are stripped to a valid name and the original JSON key is preserved in the data-binding annotation you would add. The core caveat is unchanged from every sample-based generator: fields absent from the sample are absent from the class, so a representative sample matters.
What the output is and is not
The tool produces a compilable starting point, not a full DTO layer. It does not add validation annotations, builders, or equals/hashCode beyond what a record gives you for free. Treat it as the skeleton you then annotate for your serialisation library.
Everything runs in your browser: the JSON is parsed and walked by JavaScript, nothing is uploaded, and there is no server call. Large documents take as long as your browser needs, but they never leave the page.
Frequently Asked Questions
Does the output work with Jackson or Gson?
How are null values and mixed arrays handled?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.