drupal_json_encode

Versions
mediamosa-21
drupal_json_encode($var)

Converts a PHP variable into its Javascript equivalent.

We use HTML-safe strings, i.e. with <, > and & escaped.

See also

drupal_json_decode()

Related topics

▾ 4 functions call drupal_json_encode()

ajax_render in includes/ajax.inc
Render a commands array into JSON.
drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
drupal_json_output in includes/common.inc
Return data in JSON format.
_locale_rebuild_js in includes/locale.inc
(Re-)Creates the JavaScript translation file for a language.

Code

includes/common.inc, line 4154

<?php
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));
}
?>