Skip to content
DevTinyTools

JSON to Java POJO Generator

Turn a JSON response into Java classes that actually deserialise: primitives where a value is required, wrappers where it is optional or null, @JsonProperty for keys Java cannot name, and nested objects as static classes.

Runs entirely in your browser — your JSON is never uploaded.

0 chars
0 lines

Free generation covers up to 1,000,000 characters per document — what Pro adds. The JSON you paste never leaves the tab; inference runs in your browser.

How to generate Java classes from JSON

  1. Paste a JSON object or array or load the example: two orders whose keys disagree on nullability, which is where most generated POJOs break.
  2. Name the root and set the package The root name becomes the public class and the file name. The package is optional — leave it blank for a snippet.
  3. Choose the mapping style Jackson annotations on by default, getters and setters on by default, 2 or 4 space indent. All three change the output live.
  4. Copy or download the .java file One file with every nested class. Drop it into src/main/java and run your mapper against the same payload you pasted.

Primitive or wrapper: the decision that decides whether it parses

Java’s type system forces a choice that JSON does not: a long cannot hold null. Every field therefore has to answer “can this be absent?” before it can be declared, and getting it wrong produces the classic failure — a NullPointerException on a field the sample never showed as missing, or a silently zeroed primitive.

  • Present in every sample → primitive. long total. No boxing, no null checks, and the mapper fails loudly if the API ever stops sending it.
  • Missing from any sample → wrapper. Long total. The distinction comes from sampling every array element, not just the first: paste a single record and every field looks required.
  • ever null → wrapper. Double discount for a field that held null in one record. A primitive cannot represent that, and Jackson will throw on the null rather than coerce it.
  • Generics are always boxed. List<Long>, never List<long> — Java generics only accept reference types, which is a compile error waiting for anyone who tries.

The same rule decides boolean versus Boolean and double versus Double. Whole numbers get long rather than int because 32 bits overflow on timestamps and totals; if you know a field is small, narrowing it is a safe manual edit. Floats are double, never float, and money should not be a double at all — see the precision guide for the BigDecimal argument.

Names: the part JSON and Java refuse to share

coupon_code is not a legal Java convention, so the field becomes couponCode — and now the mapper cannot find it. The wire name has to be preserved explicitly:

  • With Jackson on (default): @JsonProperty("coupon_code") sits directly above the field, so both names survive.
  • With Jackson off: the key is kept as a trailing comment, private String couponCode; // json: coupon_code. Pick a mapper that can be configured with a naming policy, or turn the annotation back on.
  • Keys that break the rules: a key starting with a digit gets a field prefix (2fa_enabled → field2faEnabled), because an identifier cannot start with a number.

One file, nested static classes

A JSON document with four nested objects could become five Java files, since only one public top-level class is allowed per file. This generator takes the other route: nested objects become public static class declarations inside the root. The result is one file you can paste and compile, with types named after their path — Order → OrderCustomer → OrderItems.

When the root of the document is an array, the file models one element and says so in a comment: Java needs a class, and inventing a wrapper object the API never sends would be worse than a comment explaining List<Order>.

Every one of these decisions is only as good as the sample behind it: paste one record and nothing looks optional. The argument is laid out in your sample is not a schema, and it applies to Java unchanged. For the parts that are Jackson-specific — primitive versus boxed, null versus absent, records and nested classes — read primitive or boxed, and why it matters.

DevTinyTools Pro

The free generator handles the payloads most people paste by hand. Pro raises the document cap and unlocks every other tool on the site:

  • 10,000,000-character documents, roughly 10 MB of JSON
  • The same Pro licence unlocks every tool on the site — TypeScript, Go, schemas, batch ZIP export
  • Priority fixes — generation bugs move to the front of the queue

Pro is $29 one-time — a lifetime licence, sold through Lemon Squeezy as merchant of record, so VAT and sales tax are handled for you. Pro is a licence key — there is still no account. Buy DevTinyTools Pro, then activate it below and the higher limits unlock in this browser.

Frequently asked questions

Why are some fields long and others Long?
A primitive long cannot hold null, so a field that is missing from some records or null in any of them is declared as the wrapper Long. Required whole numbers stay primitive to avoid pointless boxing; the same rule applies to boolean versus Boolean and double versus Double.
Why does the generator add @JsonProperty?
Because Java naming and JSON naming rarely agree. coupon_code becomes couponCode for the field, and the annotation keeps the wire name so Jackson still finds it. Without the annotation the field would silently stay null, which is the failure mode this tool exists to prevent. Turn Jackson off if you use Gson or a mapper that reads field names only — the JSON key is then kept as a comment.
Why are the nested classes inside the root class?
Java allows one public top-level class per file, so a document with four nested objects would become five files. Emitting them as public static nested classes keeps the whole document in one compilable file; promote them to top-level classes later if you prefer.
What happens to a key that is sometimes a string and sometimes a number?
It becomes Object. Java has no union types, and picking one of the two would make deserialisation fail at runtime with a confusing error. Object is honest: you will handle the type check where you read the value.
Can I use this with Gson, Moshi or kotlinx.serialization?
Yes for Gson and Moshi, with the Jackson checkbox off: the field names alone will not match snake_case keys, so keep the comments as a reminder or configure a field naming policy such as LOWER_CASE_WITH_UNDERSCORES. kotlinx.serialization needs Kotlin data classes, which is a different output.
Are records or Lombok supported?
Not yet. Java records cannot express mutable POJOs with optional fields cleanly, and Lombok would add a compile-time dependency the generated file cannot guarantee. Plain fields with getters and setters compile everywhere — turn the accessors toggle off if your mapper sets fields directly.
What about dates and enums?
JSON has neither, so an ISO-8601 string stays String and a status field stays String. Typing it as LocalDateTime or an enum would be a guess from one sample; both are five-line edits after generation, and safer done by hand.
Is my JSON uploaded?
No. Parsing, inference and code generation run in the tab. The file picker uses FileReader, and no request is made during generation — you can confirm that in the network panel.
JSON RepairFix broken JSON from an assistant or a config file: fences, comments, single quotes, trailing commas, Python literals and truncated tails — with every change reported.JSON Formatter & ValidatorPretty-print JSON with 2 or 4 space indentation, check the syntax and copy or download the result.JSON ValidatorCheck whether a JSON document is valid and see exactly where the parser stopped.JSON MinifierStrip whitespace from JSON and see how many bytes the minified output saves.JSON Diff CheckerCompare two documents and list every added, removed and changed value with its path.JSON Escape & UnescapeTurn raw text into a JSON string value, or decode backslashes and \u escapes back into readable text.JSON to CSV ConverterTurn an array of JSON objects into a CSV file you can open in a spreadsheet.JSON to TypeScript GeneratorGenerate TypeScript interfaces from a JSON sample, with optional properties and unions inferred from every array element.JSON to Go Struct GeneratorGenerate Go structs from a JSON sample, with json tags, int64 or float64 widths, pointers for null fields and omitempty for optional keys.CSV to JSON ConverterConvert CSV to JSON with RFC 4180 parsing, delimiter detection, dotted headers unflattened into nested objects and numbers converted only when they round-trip exactly.JSON to YAML Converter (and back)Convert JSON to YAML or YAML to JSON in both directions, with multi-document support, error line numbers and YAML 1.2 typing rules.JSON to Python Class GeneratorGenerate Pydantic v2 models or dataclasses from JSON, with snake_case fields, Optional where a key is missing or null, and keyword keys renamed safely.JSON to C# Class GeneratorGenerate C# classes from JSON with nullable annotations taken from every record, initialisers that avoid CS8618 and [JsonPropertyName] for each wire key.JSON to JSON Schema GeneratorTurn a JSON sample into a draft 2020-12 schema: required keys, nullable unions and nested $defs.