title: How can I write to json using org.json
body: <p>Hey so I'm trying to write json files and I can't seem a source anywhere explaining why the whole file gets overridden and gets back to square one, this is the code I happen to be using.</p>
  <pre><code>            JSONObject j = new JSONObject();
          j.put(&quot;name&quot;, member.getUser().getName());
  
          JSONObject group = new JSONObject();
          group.put(String.valueOf(Math.random()), j);
  
          String fileName = &quot;test.json&quot;;
          try (FileWriter file = new FileWriter(fileName)) {
  
              file.write(group.toString());
              file.flush();
  
          } catch (IOException e) {
              e.fillInStackTrace();
          }
  </code></pre>
  <p>My JSON file gets written like this,</p>
  <pre><code>{&quot;0.027601526266715193&quot;:{&quot;name&quot;:&quot;Keurig&quot;}}
  </code></pre>
  <p>But if I run it again it does not add another group how I want it to it just overrides the file, this is how I wanted it to be.</p>
  <pre><code>{&quot;0.027601526266715193&quot;:{&quot;name&quot;:&quot;Keurig&quot;}, &quot;0.02015264243212141&quot;:{&quot;name&quot;:&quot;Keurig&quot;}}
  </code></pre>