Write out the contents of the string str as a JSON string, escaping characters as appropriate.
340520
def write_json_string(str)
      @context.write(trans)
      trans.write(@@kJSONStringDelimiter)
      str.split('').each do |ch|
        write_json_char(ch)
      end
      trans.write(@@kJSONStringDelimiter)
    end
1218135
static void escapeJSONString(final String unsafeStr, final StringBuilder buf) {
        if (unsafeStr == null) {
            return;
        }
        // Fast path
        boolean needsEscaping = false;
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            if (c > 0xff || JSON_CHAR_REPLACEMENTS[c] != null) {
                needsEscaping = true;
                break;
            }
        }
        if (!needsEscaping) {
            buf.append(unsafeStr);
            return;
        }
        // Slow path
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            if (c > 0xff) {
                buf.append("\\u");
                final int nibble3 = ((c) & 0xf000) >> 12;
                buf.append(nibble3 <= 9 ? (char) ('0' + nibble3) : (char) ('A' + nibble3 - 10));
                final int nibble2 = ((c) & 0xf00) >> 8;
                buf.append(nibble2 <= 9 ? (char) ('0' + nibble2) : (char) ('A' + nibble2 - 10));
                final int nibble1 = ((c) & 0xf0) >> 4;
                buf.append(nibble1 <= 9 ? (char) ('0' + nibble1) : (char) ('A' + nibble1 - 10));
                final int nibble0 = ((c) & 0xf);
                buf.append(nibble0 <= 9 ? (char) ('0' + nibble0) : (char) ('A' + nibble0 - 10));
            } else {
                final String replacement = JSON_CHAR_REPLACEMENTS[c];
                if (replacement == null) {
                    buf.append(c);
                } else {
                    buf.append(replacement);
                }
            }
        }
    }
81816
private String encodeString(String str) {
        m_buffer.setLength(0);
        char ch;
        int inx = 0;
        while (inx < str.length()) {
            ch = str.charAt(inx++);
            switch (ch) {
            case '"':  m_buffer.append("\\\""); break;
            case '\\': m_buffer.append("\\\\"); break;
            case '\b':  m_buffer.append("\\b"); break;
            case '\f':  m_buffer.append("\\f"); break;
            case '\n':  m_buffer.append("\\n"); break;
            case '\r':  m_buffer.append("\\r"); break;
            case '\t':  m_buffer.append("\\t"); break;
            default:
                // All other chars are allowed as-is, despite JSON spec.
                m_buffer.append(ch);
            }
        }
        return m_buffer.toString();
    }
1009220
private void writeString(String string) throws JSONException {

// Special case for empty strings.

        if (string.length() == 0) {
            zero();
            write(end, this.stringhuff);
        } else {
            Kim kim = new Kim(string);

// Look for the string in the strings keep. If it is found, emit its
// integer and count that as a use.

            int integer = this.stringkeep.find(kim);
            if (integer != none) {
                one();
                write(integer, this.stringkeep);
            } else {

// But if it is not found, emit the string's characters. Register the string
// so that a later lookup can succeed.

                zero();
                write(kim, this.stringhuff, this.stringhuffext);
                write(end, this.stringhuff);
                this.stringkeep.register(kim);
            }
        }
    }
378171
def as_json(self, ensure_ascii=False):
        """"""
        return json.dumps(self.as_dict, ensure_ascii=ensure_ascii)
871996
def _get_json(value):
    """"""
    if hasattr(value, 'replace'):
        value = value.replace('\n', ' ')
    try:
        return json.loads(value)
    except json.JSONDecodeError:
        # Escape double quotes.
        if hasattr(value, 'replace'):
            value = value.replace('"', '\\"')
        # try putting the value into a string
        return json.loads('"{}"'.format(value))
236213
def save_json(object, handle, indent=2):
    """"""
    obj_json = json.dumps(object, indent=indent, cls=NumpyJSONEncoder)
    handle.write(obj_json)
1060298
private static void toJSONString(OutputAccessor out, Object value) {

        if (value == null) {
            out.write(NULL);
            return;
        }

        if (value instanceof String) {
            out.write((byte) '\"');
            writeUtf8(out, (String) value);
            out.write((byte) '\"');
            return;
        }

        if (value instanceof Double) {
            Double d = (Double) value;
            if (d.isNaN()) {
                out.write((byte) '\"');
                out.write(NaN);
                out.write((byte) '\"');
            } else if (d.isInfinite()) {
                out.write((byte) '\"');
                if (d == Double.NEGATIVE_INFINITY) {
                    out.write('-');

                }
                out.write(Infinite);
                out.write((byte) '\"');
            } else {
                writeAscii(out, value.toString());

            }
            return;
        }

        if (value instanceof Float) {
            Float f = (Float) value;
            if (f.isNaN()) {
                out.write((byte) '\"');
                out.write(NaN);
                out.write((byte) '\"');
            } else if (f.isInfinite()) {
                out.write((byte) '\"');
                if (f == Float.NEGATIVE_INFINITY) {
                    out.write('-');

                }
                out.write(Infinite);
                out.write((byte) '\"');
            } else {
                writeAscii(out, value.toString());

            }
            return;
        }

        if (value instanceof Number) {
            writeAscii(out, value.toString());
        }

        if (value instanceof Boolean) {

            if ((Boolean) value) {
                out.write(TRUE);
            } else {
                out.write(FALSE);
            }
        }
    }
839871
def json_escape_string(s)
      return s if s !~ /["\\\b\f\n\r\t]/

      result = ""
      s.split("").each do |c|
        case c
        when '"', "\\"
          result << "\\" << c
        when "\n" then result << "\\n"
        when "\t" then result << "\\t"
        when "\r" then result << "\\r"
        when "\f" then result << "\\f"
        when "\b" then result << "\\b"
        else
          result << c
        end
      end
      result
    end
1305574
public final void printJsonString(CharSequence text)
        throws IOException
    {
        if (text == null)
        {
            appendAscii("null");
        }
        else
        {
            appendAscii('"');
            printCodePoints(text, JSON_ESCAPE_CODES);
            appendAscii('"');
        }
    }
1374383
public static String escapeJson(@Nullable String string) {
        if (StringUtils.isEmpty(string)) {
            return "";
        }

        int len = string.length();
        StringBuilder sb = new StringBuilder(len + 2);

        for (int i = 0; i < len; i += 1) {
            char c = string.charAt(i);
            switch (c) {
                case '\\':
                case '"':
                    sb.append('\\');
                    sb.append(c);
                    break;
                case '\b':
                    sb.append("\\b");
                    break;
                case '\t':
                    sb.append("\\t");
                    break;
                case '\n':
                    sb.append("\\n");
                    break;
                case '\f':
                    sb.append("\\f");
                    break;
                case '\r':
                    sb.append("\\r");
                    break;
                default:
                    if (c < ' ') {
                        String t = "000" + Integer.toHexString(c);
                        sb.append("\\u").append(t.substring(t.length() - 4));
                    } else {
                        sb.append(c);
                    }
            }
        }
        return sb.toString();
    }
132868
def write_str(self, s):
        """"""
        self.write(s)
        self.room -= len(s)
1299491
def outputjson(self, obj):
        
        self.header('Content-Type', 'application/json')
        self.outputdata(json.dumps(obj).encode('ascii'))
1085451
def _write_json(self, message, extra):
        '''
        
        '''
        self.logger.info(message, extra=extra)
670840
def _write_jsonl(filepath, data, kwargs):
    """"""
    with io_stl.open(filepath, 'w', encoding='utf8') as outfile:
        kwargs['indent'] = None  # JSON has to be on one line!
        if 'sort_keys' not in kwargs:
            kwargs['sort_keys'] = True
        if 'separators' not in kwargs:
            kwargs['separators'] = (',', ': ')
        if 'ensure_ascii' not in kwargs:
            kwargs['ensure_ascii'] = False
        for line in data:
            str_ = json.dumps(line, **kwargs)
            outfile.write(to_unicode(str_))
            outfile.write(u'\n')
    return data
470517
private static String escapeJSON(String text) {
        StringBuilder builder = new StringBuilder();

        builder.append('"');
        for (int index = 0; index < text.length(); index++) {
            char chr = text.charAt(index);

            switch (chr) {
                case '"':
                case '\\':
                    builder.append('\\');
                    builder.append(chr);
                    break;
                case '\b':
                    builder.append("\\b");
                    break;
                case '\t':
                    builder.append("\\t");
                    break;
                case '\n':
                    builder.append("\\n");
                    break;
                case '\r':
                    builder.append("\\r");
                    break;
                default:
                    if (chr < ' ') {
                        String t = "000" + Integer.toHexString(chr);
                        builder.append("\\u" + t.substring(t.length() - 4));
                    } else {
                        builder.append(chr);
                    }
                    break;
            }
        }
        builder.append('"');

        return builder.toString();
    }
1306076
static String escape(String s) {
    String json = new JsonStringWriter().value(s).write();
    return json.substring(1, json.length() - 1);
  }