I am trying to append a class object to the existing json file using java but getting following output:
[{"email_id":"[email protected]","password":"Password ","user_name":"Anubhav Singh"}] {"email_id":"[email protected]","password":"madhav1234", "user_name":"Madhav kumar"}
But the expected output should be:
[{"email_id":"[email protected]", "password":"Password ","user_name":"Anubhav Singh"},{"email_id":"[email protected]","password":"madhav1234","user_name":"Madhav kumar"}]
My code:
FileWriter file = new FileWriter("/home/anubhav55182/NetBeansProjects/Tweetoria/src/java/Signup/data.json",Boolean.TRUE);//output json file
JSONObject obj = new JSONObject();//for json file generation
obj.put("user_name",name);
obj.put("user_id",username);
obj.put("email_id",email);
obj.put("password",pass);
file.write(obj.toJSONString());
file.flush();
Could someone help me to append new object to existing json file using java.
Thanks in advance for your help.