JSON to Java Class Converter
Paste a representative JSON object or array and generate dependency-free Java classes with nested static types and List<T> fields. Your sample stays in the browser.
How to use it
- Paste a valid and representative JSON object or array, or select Load Example.
- Choose a valid root class name such as
UserResponse. - Select Generate Java or press Ctrl/⌘ + Enter.
- Copy or download the result, then review every inferred type against the real API contract.
JSON to Java example
A sample API response can contain primitives, arrays, and nested objects:
{
"id": 42,
"name": "Ada",
"active": true,
"roles": ["admin", "editor"],
"address": {"city": "London", "postal_code": "SW1A"}
}
The converter creates a public root class, a nested static Address class, primitive fields for known booleans and numbers, and List<String> for the homogeneous roles array. Nested classes stay inside the root type so the result can be copied into one source file without creating several top-level files.
Java type inference rules
JSON strings become String, booleans become boolean, integers become long, and decimal numbers become double. A homogeneous array becomes List<T>; primitive element types are boxed as Long, Double, or Boolean because Java generics cannot use primitives. Empty and mixed arrays fall back to List<Object>.
A JSON null value becomes Object. That is intentionally conservative: one sample cannot tell whether the production field is a nullable string, number, object, or array. Replace it with the contract’s real type, and consider boxed types when a primitive field can be absent or null.
Field names and JSON mapping
JSON keys are converted into Java-compatible camelCase identifiers. Reserved words receive an underscore prefix, and keys beginning with a number are made safe. When the generated identifier differs from the original key, an inline comment records the JSON name. The class itself contains public fields and no mapping-library dependency.
For actual deserialization, configure the library used by your project. Jackson commonly uses property annotations and naming strategies; Gson has its own mapping annotations. Cryonel does not add either dependency because the correct choice depends on the application. Add annotations where a sanitized field name or naming policy differs from the payload.
Single-sample limitations
Inference only sees the values present in the pasted document. If one response contains an integer and another contains null, the first sample alone cannot describe both. The same applies to optional properties, polymorphic objects, date strings, UUID strings, and numeric identifiers that should remain strings. Generate a starting shape, then compare it with the OpenAPI or JSON Schema contract before using it in production.
Security and privacy
Conversion is performed entirely in the current tab. Cryonel does not upload the JSON sample. Generated source can still expose private field names or example values if shared alongside the original input, so remove sensitive samples from tickets, commits, and chat logs.
Frequently Asked Questions
Does the generated Java class deserialize JSON automatically?
No. It provides a dependency-free type shape. Add Jackson, Gson, or another mapper and its annotations when your application needs deserialization.
How are JSON arrays converted to Java?
Homogeneous arrays become List<T>. Empty or mixed-type arrays become List<Object> because one sample cannot prove a narrower safe type.
What type is generated for JSON null?
Null becomes Object because the sample does not reveal the value's intended non-null type.