[Solved] How to create following JSON using JSONObject java?

[ad_1]

Your question is unclear but if you just want an example of JSONObject then the code below can generate what you want.

JSONObject car = new JSONObject();
car.put("car", new JSONObject());

JSONArray brands = new JSONArray();
brands.put("C");
brands.put("D");
car.put("brands", brands);

JSONArray cars = new JSONArray();
cars.put(car);

JSONObject json = new JSONObject();
json.put("cars", cars);

System.out.println(json.toString(2));

The output is

{
  "cars": [
    {
      "car": {},
      "brands": [
        "C",
        "D"
      ]
    }
  ]
}

[ad_2]

solved How to create following JSON using JSONObject java?