/

JSON to Java

Processed Client Side

Generate Java POJOs from a JSON sample — getters and setters, Lombok, or records, with optional Jackson annotations.

JSON · 14 lines
14 lines · 216 chars
Length: 216Lines: 14Size: 216 BytesCursor: 1:1
Java
Java
javaLength: 2105Lines: 112Size: 2105 BytesCursor: 1:1

Bookmark this tool now — skip the search next time you need it.

About JSON to Java

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

The JSON to Java converter turns a sample JSON payload into Java classes you can deserialize straight into with Jackson or Gson. Nested objects become their own types, emitted as static nested classes so the entire model stays in a single .java file that compiles as-is. Arrays become List<T>, and numbers are mapped to int, long, or double from the values actually present. Keys become camelCase fields with @JsonProperty where the Java name differs from the wire name, and you can generate plain POJOs with getters, Lombok-annotated classes, or Java records depending on what your codebase uses.

Key features

  • Three output styles: POJOs with getters and setters, Lombok-annotated classes, or Java records
  • Optional @JsonProperty annotations, emitted only where the Java field name differs from the JSON key
  • Optional package declaration, with imports added only when the model actually needs them
  • Nested objects emitted as static nested classes, so the whole model is one compilable file
  • Arrays of objects merged into a single type, with fields missing from some elements marked nullable
  • Boxed wrapper types (Integer, Boolean, Double) used for nullable fields and inside generics, primitives everywhere else
  • Numeric types inferred from the data — int, long past Int32 range, double for any fractional value
  • Java reserved words handled: a field that would be called class or public gets a trailing underscore instead of failing to compile
  • Syntax-highlighted Java output and one-click copy, generated entirely in your browser

How to use it

  1. Paste a representative JSON response into the input pane.
  2. Set the root class name, and a package such as com.example.model if you want the declaration emitted.
  3. Pick the style — getters, Lombok, or record — and switch Jackson annotations on or off.
  4. Press Convert and read the generated classes.
  5. Copy the file into your project and deserialize with objectMapper.readValue(json, Root.class).

Tips & common mistakes

  • Paste the fullest sample you can find. Fields that are null in your only sample come out as Object, and empty arrays come out as List<Object>.
  • Nullable fields deliberately use Integer rather than int. A primitive cannot hold null, so an absent number would silently deserialize as 0 and hide a missing value.
  • Records are immutable and need Jackson 2.12 or later to deserialize without extra configuration. If you are on an older version, or a framework needs a no-args constructor, choose getters instead.
  • Lombok keeps the file short but requires the dependency and IDE plugin. Plain getters are the safer default for code that will be read more often than it is written.
  • Keep @JsonProperty on unless you have configured a global naming strategy. Without either, a snake_case key will not bind to a camelCase field and you will get a null with no error.
  • A key that appears with different types across samples becomes Object, because no single static type covers both. Fixing that on the API side is usually better than working around it in the model.
  • Working in C# instead? The JSON to C# converter runs the same analysis and emits classes or records with System.Text.Json or Newtonsoft attributes.

Related tools

Browse all 24 JSON tools

Frequently asked questions

10

Paste a sample JSON response, set the root class name and optionally a package, pick the style, and press Convert. Copy the result into your project and deserialize with objectMapper.readValue(json, Root.class).

Plain POJOs with getters and setters, Lombok-annotated classes, and Java records. Records need Jackson 2.12 or later to deserialize without extra configuration.

So the whole model compiles as a single .java file. A non-static inner class needs an enclosing instance, which is not something a deserializer can provide.

Yes, unless you have configured a global naming strategy. Without either, a snake_case key will not bind to a camelCase field and the value arrives as null with no error.

Because they can be null. A primitive cannot hold null, so an absent number would silently deserialize as 0 — the boxed type keeps the missing value visible.

Every element is merged into one class, so elements with slightly different shapes still produce a single type. Fields present in only some elements are marked nullable.

It was null in every sample, or it held different types across samples. No single static type covers either case, so it falls back to Object.

Java reserved words get a trailing underscore, so a key named class becomes a field named class_ with a @JsonProperty annotation preserving the original name.

No. Everything runs in your browser, so pasting a real API response with production data is safe.

The JSON to C# converter runs the same analysis and emits classes or records with System.Text.Json or Newtonsoft attributes.