JSON to Java
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
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?
- Paste a JSON sample.
- Set the root type name, for example Order.
- 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:
- JSON to C#
- JSON to Python
- JSON to Kotlin
- JSON to Swift
- JSON to Dart
- JSON to Rust
- JSON to PHP
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- JSON to Pydantic
- JSON to TypeBox
- JSON to Valibot
- JSON to Yup
- TOML to JSON
- JSON Lines / NDJSON
- UUID generator
- JSON hash
- CSS formatter
- JavaScript formatter
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
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