chain
java
JSON to Java error
⌃⏎ run · clear · / focus input
// about this tool

JSON to Java Online

Updated 2026-08-04

// how to use

  1. 1 Paste your JSON — an array of objects lets optional fields be detected.
  2. 2 Set the root name; nested objects become their own records.
  3. 3 Copy each record into its own file, or keep them nested inside one class.

// examples

A flat object
Input
{"user_id": 7, "name": "Ada"}
Output
public record Root with @JsonProperty("user_id") int userId
An optional field
Input
[{"id": 1}, {"id": 2, "note": "rush"}]
Output
note is a String component; boxed types are used where a value may be absent
A nested object
Input
{"address": {"city": "London"}}
Output
A separate Address record, referenced from the root

// common uses

Turning an API response into records without hand-writing them Getting Jackson annotations right for snake_case payloads Scaffolding DTOs for a new service integration Working out which fields a third-party API always returns

// faq

Why records rather than POJOs with getters?
Records are the modern shape for a DTO — immutable, no boilerplate, and Jackson has supported them since 2.12. If you are on an older Java, converting a record to a class with getters is mechanical.
Why are optional numbers Integer rather than int?
A primitive int cannot represent an absent key; it would read as 0 whether the field was missing or genuinely 0. Fields that appear in every record stay primitive, so you only pay for boxing where it buys you something.
What is @JsonProperty for?
Jackson maps JSON keys to component names, and a snake_case key will not match a camelCase component on its own. The annotation is added wherever the two differ, and omitted where they already match.
Should each record go in its own file?
For top-level records, yes — Java requires a public type to live in a file of the same name. Alternatively nest them inside one containing class as static records.
Is my JSON uploaded?
No. Everything runs in your browser, so the JSON never leaves your machine.

Use this via API

Get a free API key →
curl -X POST https://thesnaptools.com/api/v1/tools/json-to-java \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json":"{\"user_id\": 7, \"name\": \"Ada\"}"}'
Esc
↑↓ navigate open Esc close