JSON to Java Converter – Free, Online, Private
Generate Java records from a JSON sample, with Jackson property names when the JSON key is not a legal Java identifier.
How to convert JSON to Java
- Paste the JSON body your service decoded.
- Copy the records. Nested objects are separate record types.
- Add the Jackson dependency only if a key needed @JsonProperty.
Records, not mutable beans
The output is a Java record per object: a name, a component list, and no setters. That matches how most new code holds a JSON body. Integers become Long, other numbers Double, strings String, booleans Boolean. Boxed types are used so a future null does not require a rewrite from long to Long. Nested objects are their own records, referenced by name. Arrays become List of the element type. The generator adds an import for java.util.List and for Jackson's JsonProperty when a component name cannot stay identical to the JSON key.
Names
Component names are camelCase. A key that is already a legal identifier and uses the characters Java accepts can be kept. A key like zip-code cannot be a component name, so the record uses zipCode and a @JsonProperty annotation carries the wire name. Without that annotation Jackson would look for the wrong field. The root record is named Root. Rename it to the resource it represents. Records are implicitly final and give you constructor, equals, hashCode and accessors. They are a poor fit for a payload you must mutate; use a class if you need that.
Worked example
Root(Long id, String name, Boolean active, List<String> tags, Address address) and Address(String city, String zip) cover the sample. tags is a list of strings. There is no package line, so you can paste the records into the package you already have. Jackson will bind a matching JSON body with readValue if the names line up. A missing JSON key leaves the component null for boxed types only when you configure the mapper to allow it; records still require a value at construction time inside Java code.
What a sample cannot tell you
Optional vs required is not a Java record feature. Every component is in the constructor. Validation annotations such as NotNull are not invented. Dates stay String. An enum is not inferred from a handful of strings, because the sample cannot list the legal set. Large integer ids past the safe JavaScript range are already corrupted in the page's JSON.parse. Prefer strings for those ids on the wire. The conversion stays in the browser.
Frequently asked questions
Why records instead of classes?
A JSON body is data. Records express that with less boilerplate than a bean with getters and setters.
Do I need Jackson?
Only to read JSON at runtime, and the import is included when a @JsonProperty is required. The snippet itself is plain Java.
How are lists typed?
List of the element type inferred from the array. An empty array cannot be typed more tightly than a broad element type.
Is the payload uploaded?
No. Records are rendered locally from the parsed value.