code: public JSONObject putOnce(String key, Object value) throws JSONException {
          if (key != null && value != null) {
              if (this.opt(key) != null) {
                  throw new JSONException("Duplicate key \"" + key + "\"");
              }
              return this.put(key, value);
          }
          return this;
      }
docs: Put a key/value pair in the JSONObject, but only if the key and the value
  are both non-null, and only if there is not already a member with that
  name.
  
  @param key
  key to insert into
  @param value
  value to insert
  @return this.
  @throws JSONException
  if the key is a duplicate