Skip to content

JSON to Java Classes: POJOs from a Sample

Paste or open JSON and get Java classes with getters and setters; nothing is uploaded.

Processed on your device. Nothing is uploadedHow to check

Try a sample file:

You can also paste JSON with Ctrl+V (⌘+V on a Mac).

Your file is opened in this browser tab only: it is never uploaded or stored anywhere, and it is gone when you close the tab.

  • JSONView and edit.json

Also works with CSV, TXT, Excel, Word, PDF, Image, and PowerPoint files

Paste text instead

Pasted text stays in this tab and is never sent anywhere.

Mapping a JSON response to Java usually starts with a pile of boilerplate: a class for each object, a private field for each key, and a getter and setter for every field. Open or paste the JSON and the page writes it for you as plain classes with no annotations, such as private long id with getID() and setID(). Nested objects get their own classes, arrays become lists typed by their items, such as List<String>, whole numbers become long and decimals double. Copy the classes into your project or download a .java file. The code is generated in your browser, so nothing about your data reaches a server.

Why use JSON to Java

  • Private

    Your JSON is read and the classes are written by your own browser; nothing is sent to a server.

  • No boilerplate to type

    Plain classes with a private field, a getter and a setter for every key, and no library to depend on.

  • Works offline

    After you have used it once, it keeps working without an internet connection.

How it works: generate Java classes from JSON

  1. Open or paste JSON

    Choose or drop a .json file, paste the text into the box, or try a sample.

  2. Read the classes

    The Java code is shown at once: one class per kind of object, each with fields, getters and setters.

  3. Copy or download

    Copy the code or download a .java file, change the package from com.example to yours, and split the classes into their own files if needed.

What the JSON to Java generator handles

  • Objects: one plain class each, with a private field plus a getter and a setter per key.
  • Names: keys such as order_id or first-name become camel-case fields, with getters and setters named to match.
  • Numbers: long for whole numbers, double as soon as a value has a decimal part.
  • Arrays: lists typed by their items, such as List<String> or List<Item>; objects in one array merge into one class.
  • A value that is null everywhere in the sample becomes Object.
  • Input from a .json file, a drop, the paste box or a sample, up to 10 MB.

JSON to Java: what it can't do

  • No annotations are written and the original JSON key is not kept, so snake_case or dashed keys need a naming strategy or annotations you add.
  • Every class is in one file that starts with // Root.java and package com.example; Java wants each public class in a file of its own.
  • Types come from one sample: a field that is only ever null in it becomes Object.
  • Very large documents may take a few seconds; files up to 10 MB.

JSON to Java classes: questions and answers

Is my file uploaded?
No. The JSON is read and the Java code is generated by your browser, on your device. Pasted text stays in this tab and is never sent anywhere.
Why getters and setters instead of public fields?
Most Java libraries that read JSON into objects, and most code styles, expect private fields with getters and setters. If you prefer records or Lombok, the field names and types carry over.
Why long and not int?
A JSON number can be larger than an int holds, for example an ID or a timestamp in milliseconds. long is the safe choice; change a field to int by hand where you know the values are small.
My keys are snake_case. Will Jackson still fill the fields?
Not on its own, because the fields are camelCase and carry no annotations. Set a naming strategy, such as PropertyNamingStrategies.SNAKE_CASE on your ObjectMapper, or add @JsonProperty("order_id") to the fields that differ.
How do I read JSON into the classes?
Put the classes in your project and pass the top-level class to the library's read method, such as objectMapper.readValue(json, Root.class) with Jackson or gson.fromJson(json, Root.class) with Gson.
The code is one file. Will it compile?
Not as it is: Java allows only one public top-level class per file, and each class comes with its own package line. Move each class into a file named after it, as the // Root.java comments show, and it compiles.
How do I convert JSON to a Java class?
Paste JSON into OpenAnyDoc's JSON to Java generator and the classes appear at once, one per kind of object, each with fields, getters and setters. Copy them or download a .java file and change the package to yours; the JSON is never uploaded.

Why it's private: your files never leave your browser

Most online viewers upload your file to a server, so a copy of it leaves your device. OpenAnyDoc works the other way round: your browser reads the file and draws it on your screen. Nothing is uploaded, there is no account, and the file is gone from memory when you close the tab, so there is nothing for us to store, see or lose.

How we tell you about new features

Announcements are based on the release date shown to everyone, and nothing is stored on your device or sent anywhere.