code: public static CharSequence jsonEscape(CharSequence v) {
      int length = v.length();
      if (length == 0) return v;
  
      int afterReplacement = 0;
      StringBuilder builder = null;
      for (int i = 0; i < length; i++) {
        char c = v.charAt(i);
        String replacement;
        if (c < 0x80) {
          replacement = REPLACEMENT_CHARS[c];
          if (replacement == null) continue;
        } else if (c == '\u2028') {
          replacement = U2028;
        } else if (c == '\u2029') {
          replacement = U2029;
        } else {
          continue;
        }
        if (afterReplacement < i) { // write characters between the last replacement and now
          if (builder == null) builder = new StringBuilder(length);
          builder.append(v, afterReplacement, i);
        }
        if (builder == null) builder = new StringBuilder(length);
        builder.append(replacement);
        afterReplacement = i + 1;
      }
      if (builder == null) return v; // then we didn't escape anything
  
      if (afterReplacement < length) {
        builder.append(v, afterReplacement, length);
      }
      return builder;
    }
docs: Exposed for ElasticSearch HttpBulkIndexer