diff --git a/includes/common.inc b/includes/common.inc
index 8575844..62db714 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -4802,8 +4802,8 @@ function drupal_clear_js_cache() {
  * @ingroup php_wrappers
  */
 function drupal_json_encode($var) {
-  // json_encode() does not escape <, > and &, so we do it with str_replace().
-  return str_replace(array('<', '>', '&'), array('\u003c', '\u003e', '\u0026'), json_encode($var));
+  // json_encode() escapes <, >, ', ", and &.
+  return json_encode($var, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
 }
 
 /**
