Convert JSON to Java
Turn a sample response into Java records.
About this converter
Records rather than classes, because these are data carriers and a record says so in a fraction of the lines. Jackson and Gson both bind to them directly on any current Java.
Every type is boxed — Double and Boolean rather than double and boolean — because any JSON value can be null and a primitive cannot hold one. A primitive field would decode a missing number as 0, which is a real value and indistinguishable from a real zero.
One record per nested object, named after the key that holds it. If you need classes instead, the field list is the part that takes the time and it transfers directly.
Frequently asked questions
Why records rather than classes?
Because these types exist to carry data, which is exactly what a record is for — the constructor, accessors, equals, hashCode and toString all come free. If your codebase needs mutable classes or Lombok, the field list is the part worth generating and it copies across unchanged.
Why is every number a Double?
JSON has one number type, so a sample cannot tell an integer from a rounded decimal. Double holds both without losing anything. Change the ones you know are whole numbers to Integer or Long — and note that Long matters for identifiers beyond about nine quadrillion.
Why not int and boolean?
Because a primitive cannot be null, and any field in a JSON response can be. A missing number decoded into an int becomes 0, which looks like a real value and is not. The boxed types keep absent and zero distinguishable.
Does what I paste get sent anywhere?
No. Everything runs in your browser, on your own machine. Nothing is uploaded and nothing is logged. That matters more here than on most pages — source code, database queries and internal data are exactly the things that get pasted into tools like this, and most of them are a form that posts to a server.