Gson is another popular library for dealing with JSON in Java. It’s known for its ease of use and flexibility.
Source Code
// Assuming Gson is added to your project
Gson gson = new Gson();
Map personMap = new HashMap();
personMap.put("name", "John");
personMap.put("age", 30);
String json = gson.toJson(personMap);
System.out.println(json);