code: public static String quote(String string) {
  		StringWriter sw = new StringWriter();
  		synchronized (sw.getBuffer()) {
  			try {
  				return quote(string, sw).toString();
  			} catch (IOException ignored) {
  				// will never happen - we are writing to a string writer
  				return "";
  			}
  		}
  	}
docs: Following two methods copied from http://www.json.org/java/org/json/JSONObject.java