title: How to create multiple JSON array to JSON object in servlets
body: <p>I need to create variable amount of JSON objects and  based on the result set from a database query. States retrieving from mysql database. I am saving the response in JSON array but it is saving in multiple JSON objects like that:</p>
  
  <pre><code>    jString userid = rs2.getString("state");
      JSONObject mainObj = new JSONObject();
      JSONArray jsArray = new JSONArray();
      jsArray.put(userid );
      mainObj.put("states", jsArray);
  </code></pre>
  
  <p>With this output:</p>
  
  <pre><code>    {"states":["karnataka"]}
      {"states":["kerala"]}
      {"states":["chennai"]}
  </code></pre>
  
  <p>Can I get output in single JSON object like <code>{"States":"karnataka","kerala","chennai"}</code>?</p>