JSON to Java class
Paste JSON and get Java types for it below, as you type: records for Java 16 and later, or classes with getters and setters for any Java, ready for Jackson.
Records or classes
Records are short and immutable; classes with private fields, getters and setters suit older code and frameworks that expect JavaBeans. Pick one next to the result, and it is remembered. The first type is public, for a file of its own (Root.java); the others come along in it.
Jackson annotations
Fields are in camelCase. Where the key is written otherwise (first_name, 2fa, class), @JsonProperty gives the key, so Jackson reads and writes it as it is. Values that may be null or missing have the boxed types (Integer, Double, Boolean), which can hold null.
Types from sample data
Every item of a list, and every value of JSON Lines, is a sample of the same type: a key that some lack is optional, a value that is sometimes null is nullable, whole numbers mixed with decimals are decimals, and objects with the same keys share one type, named after the key they are under ("line_items" holds LineItem). An object whose keys are ids or dates, such as {"1001": {…}, "1002": {…}}, is a map. YAML, TOML, CSV and the other formats work too: pick their language above the editor.
Or the data as Map.ofEntries
Data writes the JSON with Map.ofEntries, Map.entry and List.of. Those take no null, so data holding one gets two small helpers instead, map(…) and list(…), which keep the nulls and the order of the keys.
Copy, download or switch
The Java follows your typing, and a mistake in the JSON is pointed out first, with its line and column. Copy or Download (a .java file) take it as it is. Above the code, switch between Types and Data, or pick another language; the Convert menu's Code item opens the one you picked last.
Private: nothing is uploaded
Formatting, checking and comparing all happen in your browser. Your documents are saved in the browser's own storage on this computer, not on a server, so they never leave your device.
With your permission, we count anonymous visits (which pages and tools are used), never what you type. See Privacy.
Questions
Which Jackson reads records?
Jackson 2.12 and later, which Spring Boot 2.5 and later bring. Classes work with any version.
Can I use Lombok?
Choose Class, then replace the getters and setters with @Data; or choose Record, which needs neither.
Is my data uploaded anywhere?
Your documents aren't: everything runs in your browser, and they are saved on your computer, in the browser's storage for this site. With your permission we count anonymous visits, never their content.
More tools
- Formatter & Converter for JSON, YAML, XML, SQL
- JSON to TypeScript – Interfaces from JSON
- JSON to Go Struct Converter
- JSON to C# Class Converter
- JSON to Python Dataclass, Pydantic & Dict
- JSON to Kotlin Data Class Converter
- JSON to Dart Model with fromJson & toJson
- JSON to Swift Codable Struct Converter
- JSON to Rust Struct Converter (serde)
- Free Online Diagram Maker & Editor
- Crypto Tools: Passwords, Keys, Hashes & JWTs
- Timestamp, Cron, Regex & UUID Utilities