Ready
Ln 1, Col 1Blog

Tool Kumar tool

JSON to Java

Convert an API example into Java records for Jackson. The root is one public record, and nested records live inside it so you can save the output in Root.java.

How to use this tool

  1. Paste a representative response, including records whose fields differ.
  2. Review the generated output and change the root name if needed.
  3. Copy or download the code, then check the types against your API contract.

Worked example

This output comes from the built-in converter. The two item prices infer a floating-point field; the null and string notes infer a nullable field.

Input

{
  "user-id": 42,
  "profile": {
    "city": "London",
    "created_at": "2026-10-14T09:00:00Z"
  },
  "items": [
    {
      "price": 12,
      "note": null
    },
    {
      "price": 12.5,
      "note": "gift"
    }
  ]
}

Output

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

public record Root(
    @JsonProperty("user-id") long userId,
    Profile profile,
    List<Item> items
) {
    public record Profile(String city, @JsonProperty("created_at") String createdAt) {}

    public record Item(double price, String note) {}
}

Use the record with Jackson

Save the default output as Root.java. Jackson constructs record components from the JSON properties. A nested record such as Item is available as Root.Item.

The output contains no package declaration. Add the package used by your application. Register your usual Jackson modules if you change dates to java.time types.

import com.fasterxml.jackson.databind.ObjectMapper;

Root model = new ObjectMapper().readValue(responseBody, Root.class);

Options and edge cases

  • This target emits records, not mutable POJOs with setters. Use Java 16 or newer and a Jackson version that supports records, such as 2.12 or newer.
  • Renamed or reserved record components get @JsonProperty with the original key. Nested object arrays become List<Item>.
  • Integers use long, large integers beyond signed 64-bit use BigInteger and fractions use double. Nullable primitives use boxed types such as Long.
  • Null-only or mixed fields use Object. Dates remain String. Use BigDecimal and a reviewed mapping when exact decimal arithmetic matters.

Private by default

Your document stays in this browser. Tool Kumar parses, converts and creates downloads on your device, with no account or upload step.

JSON to Java questions

Does JSON to Java generate POJOs?
It generates immutable Java records. If you need Java 8 POJOs, setters or a no-argument constructor, adapt the output or use a generator for that model style.
Which JSON library does it target?
Jackson. The converter imports @JsonProperty when it needs to preserve a key that differs from a Java component name.
Can I save all nested types in one file?
Yes. The public root record contains nested public records, so the default object output fits in Root.java.
How do I deserialize the record?
Use ObjectMapper.readValue(responseBody, Root.class) with Jackson record support. Review date handling and numeric limits for your API.

Related tools

JSON to Kotlin data classes, JSON to C# classes, JSON Schema generator.