JSON to Java Record Converter

Paste JSON, get immutable Java 17+ records — nested types, Jackson annotations and java.time mapping included.

In-browser & private
Advertisement
JSON Ctrl + Enter to generate
Java
Paste JSON on the left, or press Sample.
Types — Fields — Size 0 B

Records, and how the types are chosen

A record is the right shape for a payload you receive and do not mutate: the components are the API, and equals, hashCode and toString come for free. Two things are worth knowing before you paste the output into a project: records need Java 16+ (17 in practice), and Jackson binds them without an extra module only from 2.12 onwards — on anything older you need jackson-module-parameter-names or explicit @JsonProperty on every component, which is why the annotation option is on by default here.

One more, because it compiles and then fails at run time: the java.time types below need jackson-datatype-jsr310 registered on your ObjectMapper. Spring Boot does that for you; a standalone mapper does not.

JSON carries values, not types, so a converter has to infer them. This one reads every sample of a field before deciding, which is what stops a list of objects turning into a pile of near-identical records.

  • Numbers widen. A whole number becomes int, or long if it will not fit. If any sample of the same field has a decimal point, the field becomes double — or BigDecimal if you tick the box, which is the right choice for money.
  • Optional fields are boxed. A field that is null anywhere, or missing from some elements of an array, becomes Integer rather than int — otherwise the class could not hold the very document it was generated from.
  • Repeated shapes are merged. The same object appearing in several places produces one class, not Address, Address2, Address3.
  • Nested records are nested. A .java file may hold one public top-level type, so inner records are emitted inside the root — the output is one file you can paste and compile.
  • Names are converted, not renamed. full_name becomes fullName and carries @JsonProperty("full_name") so it still binds.

Need mutable classes with getters and setters instead? The JSON to Java POJO converter shares this type inference.

Frequently asked questions

Which Java version do the generated records need?
Java 16 introduced records and Java 17 is the first long-term-support release with them, so treat 17 as the floor. Switch the Style dropdown to Plain POJO or Lombok if you are on Java 8 or 11.
Do I need anything extra for Jackson to bind a record?
Jackson binds records natively from 2.12 onwards, which is what Spring Boot 2.5 and later ship. On anything older you need jackson-module-parameter-names. The generated components carry @JsonProperty anyway, so a key such as full_name binds whatever your version does with parameter names.
Why does my Instant field fail at run time?
Because java.time types need the JSR-310 module. A bare ObjectMapper answers "Java 8 date/time type not supported by default" until you add com.fasterxml.jackson.datatype:jackson-datatype-jsr310 and register JavaTimeModule. Spring Boot does both for you, which is why this usually only bites in a standalone main method. Untick "Map ISO dates to java.time" to get plain String fields instead.
What happens when the API adds a field later?
Nothing breaks. Each record is annotated @JsonIgnoreProperties(ignoreUnknown = true), so a payload that grows a property still deserialises instead of throwing UnrecognizedPropertyException. Untick "Jackson annotations" if you would rather be told.
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser. Nothing you paste leaves the page, so a production payload with real customer data is safe to use here.
Can I convert a JSON array?
Yes. A top-level array is read as a list of samples of one type, and the page tells you to bind the whole document as List<YourRecord>.

More free tools