title: how to convert a List of Data to json
body: <p>I want the following json ,where <code>List&lt;form&gt;</code> will have list of <code>form_id</code>,<code>form_name</code>, how can I convert this using jsonobject, I am not getting the proper json output. Please help me with this.
  Json:</p>
  
  <pre><code>{
      "forms": [
          { "form_id": "1", "form_name": "test1" },
          { "form_id": "2", "form_name": "test2" } 
      ]
  }
  </code></pre>
  
  <p>The above is the json structure that i need it for a list.Where id ,name is a list from form object</p>
  
  <pre><code>public static JSONObject getJsonFromMyFormObject(List&lt;Form&gt; form) {
      JSONObject responseDetailsJson = new JSONObject();
      JSONArray jsonArray = null;
      System.out.println(form.size());
      for (int i = 0; i &lt; form.size(); i++) {
          JSONObject formDetailsJson = new JSONObject();
          formDetailsJson.put("form_id", form.get(i).getId());
          formDetailsJson.put("form_name", form.get(i).getName());
          jsonArray = new JSONArray();
          jsonArray.add(formDetailsJson);
      }
      responseDetailsJson.put("form", jsonArray);
      return responseDetailsJson;
  
  } 
  </code></pre>
  
  <p>Facing issue here not getting output as a list</p>