public static function encode(/*mixed*/ $data) {
    $json = json_encode($data, JSON_UNESCAPED_SLASHES);

    // Turn some special characters into their JSON representation.
    $json = str_replace(["\t", "\r", "\n"], ['\\t', '\\r', '\\n'], $json);

    return $json;
  }