forked from anshulc55/JavaTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteJSON.java
More file actions
37 lines (25 loc) · 926 Bytes
/
writeJSON.java
File metadata and controls
37 lines (25 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package utilities;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class writeJSON {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
JSONObject student1 = new JSONObject();
student1.put("studentName", "John");
student1.put("Grade", "5th");
student1.put("Location", "16th Avenue");
JSONObject student2 = new JSONObject();
student2.put("studentName", "Anna");
student2.put("Grade", "5th");
student2.put("Location", "16th Avenue");
System.out.println(student1.toJSONString());
System.out.println(student2.toJSONString());
JSONArray studentDetails = new JSONArray();
studentDetails.add(student1);
studentDetails.add(student2);
System.out.println(studentDetails.toJSONString());
JSONObject details = new JSONObject();
details.put("studentDetails", studentDetails);
System.out.println(details.toJSONString());
}
}