code: public static void addToJson(JSONObject jsonObject, String key, Object value) throws JSONException {
  		if (jsonObject == null) {
  			throw new JSONException("Can't add key '" + key + "' to a null object.");
  		}
  		if (key == null) {
  			throw new JSONException("Can't add null key.");
  		}
  		JSONValue jsonValue = null;
  		if (value != null) {
  			if (value instanceof Date) {
  				jsonValue = new JSONString(JsonService.format((Date) value));
  			} else if (value instanceof JSONValue) {
  				jsonValue = (JSONValue) value;
  			} else {
  				jsonValue = new JSONString(value.toString());
  			}
  		}
  		jsonObject.put(key, jsonValue);
  	}
docs: Add a certain object value to the given JSON object.
  
  @param jsonObject The JSON object to add the value to.
  @param key The key to be used when adding the value.
  @param value The value to attach to the key in the JSON object.
  @throws JSONException In case something went wrong while adding.