code: public JSONWriter key(String string) throws JSONException {
          if (string == null) {
              throw new JSONException("Null key.");
          }
          if (this.mode == 'k') {
              try {
                  this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
                  if (this.comma) {
                      this.writer.write(',');
                  }
                  this.writer.write(JSONObject.quote(string));
                  this.writer.write(':');
                  this.comma = false;
                  this.mode = 'o';
                  return this;
              } catch (IOException e) {
                  throw new JSONException(e);
              }
          }
          throw new JSONException("Misplaced key.");
      }
docs: Append a key. The key will be associated with the next value. In an
  object, every value must be preceded by a key.
  @param string A key string.
  @return this
  @throws JSONException If the key is out of place. For example, keys
  do not belong in arrays or if the key is null.