Encodes {@code data} as a JSON string. This applies quotes and any necessary
character escaping.
@param data the string to encode. Null will be interpreted as an empty string.
@return the quoted value
421936
public static String quote(String data) {
		if (data == null) {
			return "\"\"";
		}
		try {
			JSONStringer stringer = new JSONStringer();
			stringer.open(JSONStringer.Scope.NULL, "");
			stringer.value(data);
			stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
			return stringer.toString();
		}
		catch (JSONException e) {
			throw new AssertionError();
		}
	}
831293
function(data) {
      if (!data) {
        data = this.getContent();
      }
      return this.encoder.encryptAes(JSON.stringify(data), this.getSecret());
    }
1055656
function (data) {
    var str = '', start = true;
    var jsondata = '';
    for (var key in data) {
      if (typeof (jsondata = JSON.stringify(data[key])) === 'string') {
        str += (start? '': '&');
        str += encodeURIComponent(key) + '=' + encodeURIComponent(jsondata);
        if (start) { start = false; }
      }
    }
    return str;
  }
1052788
function(data) {
        var keys = Object.keys(data);
        var values = keys.map(function(key) {
            return escape(data[key], true);
        });

        return '(' + keys.join(', ') + ') VALUES (' + values.join(', ') + ')' 
    }
285322
private char[] encode(byte[] data) {
        char[] out = new char[((data.length + 2) / 3) * 4];
        char[] alphabet = SESSION_ID_ALPHABET;
        //
        // 3 bytes encode to 4 chars.  Output is always an even
        // multiple of 4 characters.
        //
        for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
            boolean quad = false;
            boolean trip = false;

            int val = (0xFF & (int) data[i]);
            val <<= 8;
            if ((i + 1) < data.length) {
                val |= (0xFF & (int) data[i + 1]);
                trip = true;
            }
            val <<= 8;
            if ((i + 2) < data.length) {
                val |= (0xFF & (int) data[i + 2]);
                quad = true;
            }
            out[index + 3] = alphabet[(quad ? (val & 0x3F) : 63)];
            val >>= 6;
            out[index + 2] = alphabet[(trip ? (val & 0x3F) : 63)];
            val >>= 6;
            out[index + 1] = alphabet[val & 0x3F];
            val >>= 6;
            out[index] = alphabet[val & 0x3F];
        }
        return out;
    }
1289592
public static List<String> decodeStringsFromBase64Parameter(String data) {

        data = StringUtils.replaceChars(data, BASE64_EXTRA_REPLACEMENTS, BASE64_EXTRA);
        byte[] bytes = deobfuscateBytes(Base64.decodeBase64(data));
        try {
            JSONArray json = new JSONArray(new String(bytes, "UTF-8"));
            List<String> result = Lists.newArrayList();
            for (int i = 0; i < json.length(); i++) {
                result.add(json.getString(i));
            }
            return result;
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            throw new IllegalArgumentException("Decoding failed: " + data, e);
        }
        return null;
    }
1350191
public static function EncodeJson (& $data) {
		$flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |
			(defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) |
			(defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0) |
			(defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0);
		$json = json_encode($data, $flags);
		if ($errorCode = json_last_error()) {
			$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
			throw new \RuntimeException("[".$selfClass."] ".json_last_error_msg(), $errorCode);
		}
		if (PHP_VERSION_ID < 70100) {
			$json = strtr($json, [
				"\xe2\x80\xa8" => '\u2028',
				"\xe2\x80\xa9" => '\u2029',
			]);
		}
		return $json;
	}
588971
public static String hexEncode(final byte[] data) {
        try {
            val result = Hex.encodeHex(data);
            return new String(result);
        } catch (final Exception e) {
            return null;
        }
    }
744975
public function convertToString($data) {
		if (!is_string($data)) {
			$data = @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
			// Removing null byte and double slashes from object properties
			$data = str_replace(['\\u0000', '\\\\'], ["", "\\"], $data);
		}

		return $data;
	}
120629
@FindbugsSuppressWarnings("DM_DEFAULT_ENCODING")
  public static String encodeBase64(String data) {
    final byte[] encodedBytes = Base64.encodeBase64(data.getBytes());

    return new String(encodedBytes);
  }
289559
public function encode($data): string
    {
        $encoded = \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new EncodingException(\json_last_error_msg());
        }
        return $encoded;
    }
720721
public static String hexDecode(final char[] data) {
        try {
            val result = Hex.decodeHex(data);
            return new String(result, StandardCharsets.UTF_8);
        } catch (final Exception e) {
            return null;
        }
    }
33248
public void encode(ByteBuf out, CharSequence data) {
        ObjectUtil.checkNotNull(out, "out");
        if (data instanceof AsciiString) {
            AsciiString string = (AsciiString) data;
            try {
                encodeProcessor.out = out;
                string.forEachByte(encodeProcessor);
            } catch (Exception e) {
                PlatformDependent.throwException(e);
            } finally {
                encodeProcessor.end();
            }
        } else {
            encodeSlowPath(out, data);
        }
    }
753656
protected static String
unknownToString(byte [] data) {
	StringBuffer sb = new StringBuffer();
	sb.append("\\# ");
	sb.append(data.length);
	sb.append(" ");
	sb.append(base16.toString(data));
	return sb.toString();
}
1346439
def encode_json_body(data):
    
    # support for StringIO / file - like objects
    if hasattr(data, "read"):
        return data

    response.content_type = "application/json; charset=utf-8"

    return json.dumps(
        data,
        indent=4,
        separators=(',', ': ')
    )
790281
public static String formatBytes (byte[] data) {
    // If the data exists, format it.
    if (data != null) {
      return formatBytes(data, 0, data.length, true);
    }
    // Otherwise, return an empty String as the overloaded method would have done.
    else {
      return "";
    }
  }
1363113
public static String encode(byte[] rawData) {
        StringBuilder buffer = new StringBuilder(4 * rawData.length / 3);

        int pos = 0;
        int iterations = rawData.length / 3;
        for (int i = 0; i < iterations; i++) {
            int value = ((rawData[pos++] & 0xFF) << 16) |
                    ((rawData[pos++] & 0xFF) << 8) | (rawData[pos++] & 0xFF);

            buffer.append(BASE64_ALPHABET[(value >>> 18) & 0x3F]);
            buffer.append(BASE64_ALPHABET[(value >>> 12) & 0x3F]);
            buffer.append(BASE64_ALPHABET[(value >>> 6) & 0x3F]);
            buffer.append(BASE64_ALPHABET[value & 0x3F]);
        }

        switch (rawData.length % 3) {
            case 1:
                buffer.append(BASE64_ALPHABET[(rawData[pos] >>> 2) & 0x3F]);
                buffer.append(BASE64_ALPHABET[(rawData[pos] << 4) & 0x3F]);
                buffer.append("==");
                break;
            case 2:
                int value = ((rawData[pos++] & 0xFF) << 8) | (rawData[pos] & 0xFF);
                buffer.append(BASE64_ALPHABET[(value >>> 10) & 0x3F]);
                buffer.append(BASE64_ALPHABET[(value >>> 4) & 0x3F]);
                buffer.append(BASE64_ALPHABET[(value << 2) & 0x3F]);
                buffer.append("=");
                break;
        }

        return buffer.toString();
    }