class Employee{ public Employee(String string, int i) { name = string; age = i; } String name; int age; } Employee emp = new Employee("Alice",22); JSONObject jsonObject = (JSONObject) JSONObject.toJSON(emp); String jsonString = jsonObject.toJSONString();