JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "John"); jsonObject.put("age", 25); jsonObject.put("city", "New York");
String jsonString = jsonObject.toString();
String name = jsonObject.getString("name"); int age = jsonObject.getInt("age");In this example, we retrieve the values of the "name" and "age" properties of the JSONObject created in example 1. The org.json package is a third-party library, not a part of the Java standard library. It can be downloaded from various sources, including Maven Central.