title: Using Google GSON to convert String to JSON Array
body: <p>I am using the Google GSON library to convert an ArrayList of countries into JSON:</p>
  
  <pre><code>ArrayList&lt;String&gt; countries = new ArrayList&lt;String&gt;();
  
  // arraylist gts populated
  
  Gson gson = new Gson();
  String json = gson.toJson(countries);
  </code></pre>
  
  <p>Which yields:</p>
  
  <pre><code>["AFGHANISTAN","ALBANIA","ALGERIA","ANDORRA","ANGOLA","ANGUILLA","ANTARCTICA","ANTIGUA AND BARBUDA","ARGENTINA","ARMENIA","ARUBA","ASHMORE AND CARTIER ISLANDS","AUSTRALIA","AUSTRIA","AZERBAIJAN"]
  </code></pre>
  
  <p>How can I modify my code to generate a JSON Array? For example:</p>
  
  <pre><code>[  
     {  
        "AFGHANISTAN",
        "ALBANIA",
        "ALGERIA",
        "ANDORRA",
        "ANGOLA",
        "ANGUILLA",
        "ANTARCTICA",
        "ANTIGUA AND BARBUDA",
        "ARGENTINA",
        "ARMENIA",
        "ARUBA",
        "ASHMORE AND CARTIER ISLANDS",
        "AUSTRALIA",
        "AUSTRIA",
        "AZERBAIJAN"
     }
  ]
  </code></pre>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>Here is the code that my Java client uses to parse web service responses that already contain the curly-braces. This is why I want the countries response to contain the curly braces:</p>
  
  <pre><code>Gson gson = new GsonBuilder().create();
      ArrayList&lt;Map&lt;String, String&gt;&gt; myList = gson.fromJson(result,
              new TypeToken&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt;() {
              }.getType());
  
      List&lt;Values&gt; list = new ArrayList&lt;Values&gt;();
  
      for (Map&lt;String, String&gt; m : myList) {
          list.add(new Values(m.get(attribute)));
      }
  </code></pre>