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

Type mapping

JSON valueJava type
42int (or long if large)
3.14double
"hi"String
trueboolean
nullObject
[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?
The generator emits Java 16+ records with typed fields, which Jackson 2.12+ and Gson both bind to JSON directly. For older Java, change `record` to `class` and add getters/setters. Field names mirror your JSON keys; a key that is not a legal Java identifier is sanitised, and you would add a @JsonProperty annotation to map it back.
How are null values and mixed arrays handled?
A null becomes `Object` because Java has no JSON `null` type. A JSON array whose elements are not all the same type collapses to `List<Object>`, since Java generics cannot express a union. For a precise `List<Type>`, give a sample whose array holds one element type.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close