code: @Nonnull
      public static String escapeString(@Nonnull String s) {
          // We replace double quotes with a back slash followed
          // by a double quote. We replace backslashes with a double
          // backslash
          if (s.indexOf('\"') == -1 && s.indexOf('\\') == -1) {
              return s;
          }
          StringBuilder sb = new StringBuilder(s.length() + 20);
          for (int i = 0; i < s.length(); i++) {
              char ch = s.charAt(i);
              if (ch == '\\') {
                  sb.append("\\\\");
              } else if (ch == '\"') {
                  sb.append("\\\"");
              } else {
                  sb.append(ch);
              }
          }
          return verifyNotNull(sb.toString());
      }
docs: Escapes quotes and backslashes in a string. Double quotes are replaced
  with a backslash followed by a double quote, and backslashes are replaced
  with a double backslash.
  
  @param s
  The string to be escaped
  @return The escaped string.