Skip to content
jsonforge.app

JSON to Java

Generate Java records from a JSON sample, ready to bind with Jackson.

JSON input

Loading editor…

Generated code

Enter JSON on the left to generate a type from it.

What is JSON to Java?

A JSON to Java converter turns a sample JSON payload into Java record declarations that mirror its structure. Records, added in Java 16, are the modern replacement for the hand-written POJO: a single line declares the components and the compiler generates the constructor, accessors, equals, hashCode, and toString, removing the hundred lines of boilerplate that a data class used to require. Because Jackson and other JSON binding libraries can construct records directly, this is now the shortest path from an API response to typed Java code. Generating them from a real payload also avoids the classic integration bug where a hand-typed field name differs from the JSON key by a single character and silently deserializes as null.

How to use JSON to Java

  1. Paste a representative JSON response into the left panel — the record components match exactly the keys in that sample.
  2. Set a root record name above the output (defaults to "Root"); every nested object gets its own record, named for the key that holds it.
  3. Copy the records into your project — each top-level record needs its own file if you declare it public, or they can be nested inside one class.
  4. Use the language picker above the output to emit the same shape as a Kotlin data class or C# record instead.

Examples

Flat object as a record

Input

{"id": 1, "name": "Ada", "active": true}

Output

record Root( int id, String name, boolean active ) {}

Nested object and a list

Input

{"user": {"id": 1, "name": "Ada", "roles": ["admin"]}}

Output

import java.util.List; record User( int id, String name, List<String> roles ) {} record Root( User user ) {}

Common mistakes

  • Leaving a nullable field as a primitive int or boolean — a null in the payload then either fails binding or silently becomes 0 or false, which is much harder to notice.
  • Declaring every generated record public in one file, which won't compile because Java allows only one public top-level type per file.
  • Expecting a record to be mutable — components are final by design, so code that tried to set fields after construction needs restructuring rather than a small edit.

Why use this tool

  • Produces records rather than legacy POJOs, replacing constructor, getters, equals, hashCode, and toString with a single declaration.
  • Adds the java.util.List import automatically when the payload contains arrays, so the output compiles without hunting for missing imports.
  • Runs entirely client-side, so a payload copied from a Spring Boot or Micronaut service stays on your machine instead of reaching a server.

Frequently asked questions