How to generate classes from JSON
- Paste a JSON object into the left panel, or click Load Sample.
- Pick the output language on the right: Java, TypeScript, Python, JavaScript or C#.
- For Java, choose Lombok or a plain POJO and which constructors you want.
- Click Convert, then Copy Output.
What you get
Every JSON object becomes a class, and nested objects get a class of their own, named after their key. The top-level class is called RootObject, so rename it to fit your code. In Java, C# and TypeScript, field types come from the sample values: text becomes String, whole numbers become int, decimals become double, and so on. For example, with Java and Lombok:
{ "userName": "ada", "age": 36, "address": { "city": "London" } }
produces an Address class with a city field, and a RootObject class with userName, age and address, each annotated with @Data and the constructor annotations you picked.
Tips for better results
- Use a sample where every field has a real value. A field that is
nullin the sample can't tell the generator its type. - If a number can have decimals, put a decimal value like
9.5in the sample so it isn't typed as a whole number. - Check list fields after generating. Arrays may come out as a generic
Objecttype that you'll want to change to a typed list. - Choose Snake Case output for Python if your API uses
user_namestyle keys.
Is my code sent anywhere?
Yes. The conversion runs on our server: your input is sent, converted in memory and returned. It isn't stored. See the privacy policy for details.
Frequently asked questions
Which languages can I generate?
Java (with Lombok annotations or as a plain POJO), TypeScript, Python, JavaScript and C#.
Why is my top-level class called RootObject?
JSON doesn't name its outermost object, so the generator uses RootObject. Rename it after copying the code.
How are field types chosen?
In Java, C# and TypeScript the types come from the values in your sample: text becomes a string, whole numbers an integer, decimals a double or number, and true/false a boolean. Python and JavaScript classes are generated without type annotations. A field that is null in the sample has no type to go on, so give it a real value before converting.
Does it handle nested objects?
Yes. Every nested object becomes its own class, named after its key, and the parent class gets a field of that type.