title: How to add append a new class object to the existing JSON file in Java?
body: <p>I am trying to append a class object to the existing json file using java but getting following output:</p>
  
  <blockquote>
    <p>[{"email_id":"anu55182@gmail.com","password":"Password
    ","user_name":"Anubhav Singh"}]
    {"email_id":"madhav123@gmail.com","password":"madhav1234",
    "user_name":"Madhav kumar"}</p>
  </blockquote>
  
  <p>But the expected output should be:</p>
  
  <blockquote>
    <p>[{"email_id":"anu55182@gmail.com", "password":"Password
    ","user_name":"Anubhav
    Singh"},{"email_id":"madhav123@gmail.com","password":"madhav1234","user_name":"Madhav kumar"}]</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><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();
  </code></pre>
  
  <p>Could someone help me to append new object to existing json file using java.</p>
  
  <p>Thanks in advance for your help.</p>