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.

Parameters

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

File

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

Code

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