JSON to Java Record Converter
Paste JSON, get immutable Java 17+ records — nested types, Jackson annotations and java.time mapping included.
Paste JSON on the left, or press Sample.
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, orlongif it will not fit. If any sample of the same field has a decimal point, the field becomesdouble— orBigDecimalif you tick the box, which is the right choice for money. - Optional fields are boxed. A field that is
nullanywhere, or missing from some elements of an array, becomesIntegerrather thanint— 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
.javafile 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_namebecomesfullNameand 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@JsonPropertyanyway, so a key such asfull_namebinds whatever your version does with parameter names. - Why does my
Instantfield fail at run time? - Because
java.timetypes need the JSR-310 module. A bareObjectMapperanswers "Java 8 date/time type not supported by default" until you addcom.fasterxml.jackson.datatype:jackson-datatype-jsr310and registerJavaTimeModule. 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 plainStringfields 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 throwingUnrecognizedPropertyException. 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>.