- Download the latest release.
- Add package to your build using command-line, or your IDE like Eclipse or Netbeans.
Here is an example on how to make a new JSON object:
JSONObject obj = new JSONObject();
obj.put("$id", "User-info");
obj.put("name", "Gelobt");
obj.put("age", 16);
obj.put("isAlive", true);
& here is an example on how to make a new JSON array:
JSONArray arr = new JSONArray();
arr.add("Java");
arr.add("C++");
arr.add("Cats");
then you can put this array in the JSON object you`ve just created:
obj.put("THINGS I LOVE", arr);
last but not least, write this JSON object in a JSON file:
obj.write(new File("User-info.json"));
& here is your JSON file:
{
"isAlive":true
,"name":"Gelobt"
,"THINGS I LOVE": [
"Java"
,"C++"
,"Cats"
]
,"age":16
,"$id":"User-info"
}