JSONRecord Generator
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.
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.