title: JS resultset to JSON
body: <p>I have the following code cloned from XML output. I need the output to be a JSON object instead of an XML string but am missing something.</p>
  
  <pre><code>    public String evaluate() throws Exception
  {
      String itemTitle = "";
      BoundStringBuilder data = new BoundStringBuilder();
      TreeMap promptValues = ReportItem.promptValuesSetStringToTreeMap(promptValuesSet);
      String debugFlag = isDebugMode ? "Y" : "N";
  
      // get JSON item config settings
      ExecuteProcedure ep = new ExecuteProcedure(con, "pkg_report.select_mr_JSON_config");
      ep.setParam("p_report_number", reportNumber);
      ep.setParam("p_instance_number", instanceNumber);
      ep.setParam("p_item_index", itemIndex);
      ep.setParam("p_path", null);
      ResultSet JSONConfigRs = ep.execute()[0];
      while(JSONConfigRs.next())
      {
          String setting = JSONConfigRs.getString("field_name");
          String value = UtilityMethods.nullValue(JSONConfigRs.getString("value"), "").toLowerCase();
  
          if(setting.equals("JSON_JSONREPORTITEM_ITEMNAME_BAN_ITEM_NAME"))
              itemTitle = value;
      }
      JSONConfigRs.close();
      ep.close();
  
      // execute sql
      ep = new ExecuteProcedure(con, "pkg_report.execute_mr_sql");
      ep.setParam("p_report_number", reportNumber);
      ep.setParam("p_instance_number", instanceNumber);
      ep.setParam("p_item_index", itemIndex);
      ep.setParam("p_item_type_code", itemTypeCode);
      ep.setParam("p_sub_item_index", "1");
      ep.setParam("p_sub_sub_item_index", "1");
      ep.setParam("p_prompt_values", UtilityMethods.treeMapToList(promptValues));
      ep.setParam("p_debug_flag", debugFlag);
      ResultSet rs = ep.execute()[0];
  
      ResultSetMetaData rsmd = rs.getMetaData();
      String[] columnNames = new String[rsmd.getColumnCount()];
      for(int i = 0; i &lt; columnNames.length; i++)
          columnNames[i] = rsmd.getColumnName(i + 1).toLowerCase();
  
      data.append("&lt;data name=\"").append(itemTitle).append("\"&gt;\n");
  
      while(rs.next())
      {
          data.append("\t&lt;row&gt;\n");
          for(int i = 0; i &lt; columnNames.length; i++)
          {
              data.append("\t\t&lt;cell name=\"").append(columnNames[i]).append("\"&gt;");
              data.append(UtilityMethods.xmlFormat(UtilityMethods.screenFormat(rs.getString(i + 1)).trim()));
              data.append("&lt;/cell&gt;\n");
          }
          data.append("\t&lt;/row&gt;\n");
      }
      rs.close();
      ep.close();
      data.append("&lt;/data&gt;\n");
  
      String JSONData = data.toString();
      return JSONData;
  }
  </code></pre>
  
  <p>I was advised "Instead of building up an XML string, you should use one the GSON JSON utility methods to dump the result set to a JSON object instead."</p>
  
  <p>Can someone point me in the right direction, please. I am unfamiliar with JSON Objects, if that isn't obvious enough ;)</p>