code: public static String rowToString(JSONArray ja) {
  
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < ja.length(); i += 1) {
              if (i > 0) {
                  sb.append(',');
              }
              Object o = ja.opt(i);
              if (o != null) {
                  String s = o.toString();
                  if (s.indexOf(',') >= 0) {
                      if (s.indexOf('"') >= 0) {
                          sb.append('\'');
                          sb.append(s);
                          sb.append('\'');
                      } else {
                          sb.append('"');
                          sb.append(s);
                          sb.append('"');
                      }
                  } else {
                      sb.append(s);
                  }
              }
          }
          sb.append('\n');
          return sb.toString();
  
      }
docs: Produce a comma delimited text row from a JSONArray. Values containing
  the comma character will be quoted.<p>
  
  @param ja A JSONArray of strings
  @return A string ending in NEWLINE