function drupal_json_output

drupal_json_output($var = NULL)

Returns data in JSON format.

This function should be used for JavaScript callback functions returning data in JSON format. It sets the header for JavaScript output.

Parameters

$var: (optional) If set, the variable will be converted to JSON and output.

File

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

Code

function drupal_json_output($var = NULL) {
  // We are returning JSON, so tell the browser.
  drupal_add_http_header('Content-Type', 'application/json');

  if (isset($var)) {
    echo drupal_json_encode($var);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_json_output/7.x