function drupal_json_encode

Converts a PHP variable into its JavaScript equivalent.

We use HTML-safe strings, with several characters escaped.

See also

drupal_json_decode()

Related topics

8 calls to drupal_json_encode()
ajax_render in drupal/core/includes/ajax.inc
Renders a commands array into JSON.
ContextualLinks::render in drupal/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php
Render the contextual fields.
drupal_pre_render_scripts in drupal/core/includes/common.inc
#pre_render callback to add the elements needed for JavaScript tags to be rendered.
EditIntegrationTest::testGetUntransformedTextCommand in drupal/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
Tests GetUntransformedTextCommand AJAX command.
form_test_form_state_values_clean_form_submit in drupal/core/modules/system/tests/modules/form_test/form_test.module
Form submit handler for form_state_values_clean() test form.

... See full list

File

drupal/core/includes/common.inc, line 3993
Common functions that many Drupal modules will need to reference.

Code

function drupal_json_encode($var) {

  // Encode <, >, ', &, and " using the json_encode() options parameter.
  return json_encode($var, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
}