Encode JSON string
@param {string} str
@returns {string}
516710
function encode(str) {
    var i;
    var vacs = findSingleVacancies(str, singleLen + complexLen);
    var singleReplacements = vacs.slice(0, singleLen);
    var complexReplacements = vacs.slice(singleLen);
    var dest = str;
    // first replace complex delimiters
    for (i = COMPLEX_DELIMITERS.length - 1; i >= 0; i--) {
        if (i < complexReplacements.length) {
            dest = dest.split(COMPLEX_DELIMITERS[i]).join(complexReplacements[i]);
        }
    }
    // then replace single delimiters
    for (i = 0; i < singleReplacements.length; i++) {
        dest = dest.split(SINGLE_DELIMITERS[i]).join(singleReplacements[i]);
    }
    // concatenate with replacement map
    dest = singleReplacements.join('') + SECTION_DELIMITER + complexReplacements.join('') + SECTION_DELIMITER + dest;
    return dest;
}
1214622
function encode (body) {
  var str = JSON.stringify(body)
  return Buffer.from(str).toString('base64')
}
343687
function (str) {
                str = stringify(str);
                var byteArray = [];
                for (var i = 0, l = str.length; i < l; i++) {
                    if (str.charCodeAt(i) <= 0x7F) {
                        byteArray.push(str.charCodeAt(i));
                    }
                    else {
                        var h = encodeURIComponent(str.charAt(i)).slice(1).split('%');
                        for (var j = 0; j < h.length; j++) {
                            byteArray.push(parseInt(h[j], 16));
                        }
                    }
                }
                return byteArray;
            }
1153191
function(str){
  var ret = new Array(str.length), len = str.length;
  while(len--) ret[len] = str.charCodeAt(len);
  return Uint8Array.from(ret);
}
823267
function prettifyJson(str) {
    var json = JSON.parse(str);
    return JSON.stringify(json, null, 2);
}
554562
function encode_string ($str, $encoding = "base64") {
      switch(strtolower($encoding)) {
         case "base64":
            // chunk_split is found in PHP >= 3.0.6
            $encoded = chunk_split(base64_encode($str));
            break;

         case "7bit":
         case "8bit":
            $encoded = $this->fix_eol($str);
            if (substr($encoded, -2) != "\r\n")
               $encoded .= "\r\n";
            break;

         case "binary":
            $encoded = $str;
            break;

         case "quoted-printable":
            $encoded = $this->encode_qp($str);
            break;

         default:
            $this->error_handler(sprintf("Unknown encoding: %s", $encoding));
            return false;
      }
      return($encoded);
   }
529105
function utf8Encode(str) {
  var bytes = [], offset = 0, length, char;

  str = encodeURI(str);
  length = str.length;

  while (offset < length) {
    char = str.charAt(offset);
    offset += 1;

    if (char !== '%') {
      bytes.push(char.charCodeAt(0));
    } else {
      char = str.charAt(offset) + str.charAt(offset + 1);
      bytes.push(parseInt(char, 16));
      offset += 2;
    }
  }

  return bytes;
}
1212105
function encodeAsString(obj) {
  var str = '';
  var nsp = false;

  // first is type
  str += obj.type;

  // attachments if we have them
  if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
    str += obj.attachments;
    str += '-';
  }

  // if we have a namespace other than `/`
  // we append it followed by a comma `,`
  if (obj.nsp && '/' != obj.nsp) {
    nsp = true;
    str += obj.nsp;
  }

  // immediately followed by the id
  if (null != obj.id) {
    if (nsp) {
      str += ',';
      nsp = false;
    }
    str += obj.id;
  }

  // json data
  if (null != obj.data) {
    if (nsp) str += ',';
    str += json.stringify(obj.data);
  }

  debug('encoded %j as %s', obj, str);
  return str;
}
1082790
function toJSON(d) {
    if (!_.isString(d)) {
        d = JSON.stringify(d);
    }

    return d;
}
521320
static function _json_encode($value)
    {
        static $jsonReplaces = array(
            array('\\', '/', "\n", "\t", "\r", "\b", "\f", '"'),
            array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));

        if (is_null($value)) {
            return 'null';
        }
        if ($value === false) {
            return 'false';
        }
        if ($value === true) {
            return 'true';
        }

        if (is_scalar($value)) {

            // Always use '.' for floats.
            if (is_float($value)) {
                return floatval(str_replace(',', '.', strval($value)));
            }
            if (is_string($value)) {
                return sprintf('"%s"',
                    str_replace($jsonReplaces[0], $jsonReplaces[1], $value));
            } else {
                return $value;
            }
        }

        $isList = true;
        for ($i = 0, reset($value); $i<count($value); $i++, next($value)) {
            if (key($value) !== $i) {
                $isList = false;
                break;
            }
        }
        $result = [];
        if ($isList) {
            foreach ($value as $v) {
                $result[] = self::_json_encode($v);
            }

            return '[' . join(',', $result) . ']';
        } else {
            foreach ($value as $k => $v) {
                $result[] = self::_json_encode($k) . ':' . self::_json_encode($v);
            }

            return '{' . join(',', $result) . '}';
        }
    }
645437
private static byte[] stringToByteArray(String str) {
		byte[] result = new byte[str.length() + 1];
		for (int i = 0; i < str.length(); i++) {
			result[i] = (byte) str.charAt(i);
		}
		result[str.length()] = 0;
		return result;
	}
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
954839
def utf8_encode_str(string, encoding='UTF-8'):
    
    if not string:
        return ''
    src_enc = chardet.detect(string)['encoding']
    try:
        return string.decode(src_enc).encode(encoding)
    except:
        return string.decode('ascii', errors='replace').encode(encoding)
1062795
function parse (str) {
  if (Buffer.isBuffer(str)) str = str.toString();
  type('str', str, 'String');
  try {
    return JSON.parse(str);
  } catch (ex) {
    ex.message = 'Unable to parse JSON: ' + ex.message + '\nAttempted to parse: ' + str;
    throw ex;
  }
}
17252
public static final String base64Decode(String str) {
        if (str == null) {
            return null;
        } else {
            byte data[] = getBytes(str);
            return toString(base64Decode(data));
        }
    }
1209810
function str_serialize(result, key, value) {
  // encode newlines as \r\n cause the html spec says so
  value = value.replace(/(\r)?\n/g, '\r\n');
  value = encodeURIComponent(value);

  // spaces should be '+' rather than '%20'.
  value = value.replace(/%20/g, '+');
  return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value;
}
655318
function decode(str) {
  var decoded = 0;

  for (i = 0; i < str.length; i++) {
    decoded = decoded * length + map[str.charAt(i)];
  }

  return decoded;
}