/*
 * call-seq: to_json(*)
 *
 * This string should be encoded with UTF-8 A call to this method
 * returns a JSON string encoded with UTF16 big endian characters as
 * \u????.
 */
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self)
{
    VALUE result = rb_str_buf_new(RSTRING_LEN(self));
    rb_str_buf_cat2(result, "\"");
#ifdef HAVE_RUBY_ENCODING_H
    if (rb_funcall(self, i_encoding, 0) == mEncoding_UTF_8) {
        JSON_convert_UTF8_to_JSON(result, self, strictConversion);
    } else {
        VALUE string = rb_funcall(self, i_encode, 1, mEncoding_UTF_8);
        JSON_convert_UTF8_to_JSON(result, string, strictConversion);
    }
#else
    JSON_convert_UTF8_to_JSON(result, self, strictConversion);
#endif
    rb_str_buf_cat2(result, "\"");
    FORCE_UTF8(result);
    return result;
}