title: GSON adding java objects from arraylist to existing json file?
body: <p>I have a program that currently can read from JSON file and implement these into a object, and store in a arraylist of objects. I asked a question yesterday about how to write back to the JSON file and someone suggested the .put method however this doesn't write correctly in the JSON format. For example, when there is an existing JSON object as below in the .json file:
   <code>[
    {
      "waterSpace": 4.0,
      "airSpace": 5.0,
      "landSpace": 3.0,
      "name": "robbie",
      "penType": "pen"
    }
  ]
  </code>but when I use .put to add it does the following<code>
      [
    {
      "waterSpace": 4.0,
      "airSpace": 5.0,
      "landSpace": 3.0,
      "name": "robbie",
      "penType": "pen"
    }
  ]{"waterSpace": 4.0,
      "airSpace": 5.0,
      "landSpace": 3.0,
      "name": "robbie",
      "penType": "pen"
    }</code></p>
  
  <p>How can I use GSON to add the objects from the arraylist properly so the formatting is correct and it looks like the below:
  <code>[
    {
      "waterSpace": 4.0,
      "airSpace": 5.0,
      "landSpace": 3.0,
      "name": "robbie",
      "penType": "pen"
    },{
  "waterSpace": 4.0,
      "airSpace": 5.0,
      "landSpace": 3.0,
      "name": "robbie",
      "penType": "pen"
    }
  ]</code></p>