title: Appending JSONObjects when writing to a file
body: <p>I'm trying to append <code>JSONObjects</code> inside a JSONArray that is called <code>Records</code> .</p>
  
  <p>The first time I save it it saves it this way that is ok</p>
  
  <pre><code>{
    "Records": [
      {
        "travelTime": 2,
        "totalDistance": 0,
        "pace": 0,
        "kCalBurned": 0,
        "latlng": "[lat\/lng: (-32.1521234,-63.66412321)]"
      }
    ]
  }
  </code></pre>
  
  <p>But when I try to append again a new jsonobject inside Records, it creates a new JSONArray for it, and I just want to append a new object inside records</p>
  
  <pre><code>{
    "Records": [
      {
        "travelTime": 2,
        "totalDistance": 0,
        "pace": 0,
        "kCalBurned": 0,
        "latlng": "[lat\/lng: (-31.6432292,-63.3667462)]"
      }
    ]
  }{
    "Records": [
      {
        "travelTime": 1,
        "totalDistance": 0,
        "pace": 0,
        "kCalBurned": 0,
        "latlng": "[lat\/lng: (-31.9522431,-64.3461241)]"
      }
    ]
  }
  </code></pre>
  
  <p>This is the code I use to save the <code>Records</code> </p>
  
  <pre><code>   private void writeJsonData(long travelTime,float totalDistance, float pace, float kCalBurned, LinkedList&lt;LatLng&gt; latlng){
  
          String jsonStr = "";
          JSONObject records  = new JSONObject();
          try {
              records.put("travelTime", travelTime);
              records.put("totalDistance", totalDistance);
              records.put("pace", pace);
              records.put("kCalBurned", kCalBurned);
              records.put("latlng", latlng);
  
              JSONArray jsonArray = new JSONArray();
              jsonArray.put(records);
  
              JSONObject recordsObj = new JSONObject();
              recordsObj.put("Records", jsonArray);
  
              jsonStr = recordsObj.toString();
  
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          String file_name = "records.json";
  
          FileOutputStream fileOutputStream = null;
          try {
  
              fileOutputStream = new FileOutputStream(new File(mContext.getFilesDir(),file_name),true);
              fileOutputStream.write(jsonStr.getBytes());
              fileOutputStream.close();
  
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  
      }
  </code></pre>