JSON to Java record

Paste an example JSON object and generate Java record declarations, including nested objects and arrays.

Formats JSON → JavaSteps & examples
Branches of a tree map onto the fields of a record card.

Workspace

Runs locally in your browser. No file upload.

Preset parameters

Input & settings

Paste text or edit a loaded file

Select a file or paste data to begin.

Result

Copy or download when available

Start Java records from example JSON

  1. Paste a JSON object that represents your expected data.
  2. Set the root record name and generate the declarations.
  3. Review inferred types, nested records and renamed fields before using the code.

Worked example

With root name Person, {"name":"Ana","age":30} generates a Person record with String name and Long age components. A single sample does not establish whether either field is optional.

Input and output

Paste one representative object and choose the name you want for its Java record. Compare the generated component names with the JSON keys before connecting a serializer. For a list of customer objects, start with one complete customer that includes the nested fields you expect to receive.

Format and size limits

Inference uses values present in the sample. An empty list gives no evidence of its element type, and a number written without a fractional part can look like an integer even when later records contain fractions. Compare the draft with your actual API contract.

If processing fails

If compilation or binding fails, look for keys containing punctuation, reserved Java words or two keys that normalize to the same identifier. Assign distinct component names and configure your JSON library to map them back to the original wire names.

Questions about this tool

Which Java version supports records?

Records are a standard language feature in Java 16 and later. Check your project’s Java version before using the generated declarations.

How are mixed arrays and nulls handled?

Arrays use the first non-null sample element to infer their type; null values without a type example become Object. Review heterogeneous arrays and optional fields manually.

How it works

The converter walks a sample JSON value and maps strings, booleans, integers and decimal values to Java types. Nested objects become separate records, while arrays become java.util.List of the detected element type.

Important limitations

This is schema inference from example data, not full JSON Schema compilation. Mixed-type arrays use the first non-null example. Keys with invalid Java identifiers are normalized; review renaming and optional/null semantics.