code: public JSONObject accumulate(String name, Object value) throws JSONException {
          Object current = nameValuePairs.get(checkName(name));
          if (current == null) {
              return put(name, value);
          }
  
          if (current instanceof JSONArray) {
              JSONArray array = (JSONArray) current;
              array.checkedPut(value);
          } else {
              JSONArray array = new JSONArray();
              array.checkedPut(current);
              array.checkedPut(value);
              nameValuePairs.put(name, array);
          }
          return this;
      }
docs: unhidden.