1 common.inc backdrop_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.


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


core/includes/common.inc, line 5842
Common functions that many Backdrop modules will need to reference.


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

  if (isset($var)) {
    echo backdrop_json_encode($var);