JSONRecord Generator

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.
Classes 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.

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.

More free tools