JSON to Java

Input
Output

JSON to Java

Paste a JSON sample, such as an API response, and Bracely writes Java records ready for Jackson for it. Each object becomes a Java record, with Jackson annotations where a key isn't a valid Java name.

Example: a payment event for a Spring Boot service

Two payment events from a gateway webhook. Each object becomes a record; snake_case keys get @JsonProperty on camelCase components; amount is a whole number in one event and a decimal in the other, so it becomes double; and fee, sent only with captured payments, becomes a boxed Long so it can be null:

Input

[
  {
    "event_id": "evt_9001",
    "type": "payment.captured",
    "amount": 1499,
    "fee": 30,
    "currency": "INR",
    "customer": {
      "id": "cus_77",
      "email": "[email protected]"
    },
    "captured_at": "2026-10-29T10:00:00Z"
  },
  {
    "event_id": "evt_9002",
    "type": "payment.failed",
    "amount": 799.5,
    "currency": "INR",
    "customer": {
      "id": "cus_78",
      "email": "[email protected]"
    },
    "failure_reason": "card_declined",
    "captured_at": null
  }
]

Output

import com.fasterxml.jackson.annotation.JsonProperty;

public record PaymentEvent(
    @JsonProperty("event_id") String eventId,
    String type,
    double amount,
    Long fee,
    String currency,
    Customer customer,
    @JsonProperty("captured_at") String capturedAt,
    @JsonProperty("failure_reason") String failureReason
) {}

public record Customer(
    String id,
    String email
) {}

How do I use the JSON to Java?

  1. Paste a JSON sample.
  2. Set the root type name, for example Order.
  3. Copy the Java code into your project.

What does the JSON to Java do?

  • Records with typed fields and List<> for arrays
  • Boxed types (Long, Double) for fields that can be missing
  • Jackson @JsonProperty for keys that need it
  • Nested objects become their own named types
  • 20 other languages from the same sample, including TypeScript

When to use the JSON to Java

Mapping JSON in a Spring Boot service, an Android app or any Jackson-based code needs a class per object shape. Generating them from a real payload, such as a webhook from a payment gateway, saves typing every field and gets the names and types right the first time.

Each object becomes a Java record (Java 16 and later) that Jackson can read directly. snake_case and other keys that aren't Java names keep their JSON name in @JsonProperty while the component gets a camelCase name. Whole numbers become long and decimals double; a number missing from some items becomes the boxed Long or Double so it can be null; a field whose values disagree becomes Object. Omit when empty adds @JsonInclude(JsonInclude.Include.NON_EMPTY) to the fields you list, or * for all, so empty values are left out when writing JSON.

Frequently asked questions

Records or classes?
Records: they're immutable, short and have equals, hashCode and toString built in, and Jackson 2.12 and later reads them without extra annotations. If you're on Java 11, turn each record into a class with the same fields.
Why is a number Long instead of long?
It was missing from at least one item in the sample. A primitive long can't be null, so a missing value would become 0; the boxed Long keeps the difference between 0 and absent.
How does it pick Java types?
From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
Can I generate other languages?
Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
Is my data uploaded?
No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.

More JSON tools

Bracely has 108 JSON tools in one page. Related ones:

Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram