You are here

function drupal_json_pretty_print in Open Atrium Export 7.2

Converts a PHP variable into its JavaScript equivalent.

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

COPIED FROM drupal_json_encode() in common.inc but added JSON_PRETTY_PRINT option

See also

drupal_json_decode()

drupal_json_encode_helper()

1 call to drupal_json_pretty_print()
oa_export_json_export in formats/json.inc
Export callback.

File

formats/json.inc, line 21
The OA export JSON format handler.

Code

function drupal_json_pretty_print($var) {

  // The PHP version cannot change within a request.
  static $php530;
  static $php540;
  if (!isset($php530)) {
    $php530 = version_compare(PHP_VERSION, '5.3.0', '>=');
  }
  if (!isset($php540)) {
    $php540 = version_compare(PHP_VERSION, '5.4.0', '>=');
  }
  if ($php530) {

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

  // json_encode() escapes <, >, ', &, and " using its options parameter, but
  // does not support this parameter prior to PHP 5.3.0.  Use a helper instead.
  include_once DRUPAL_ROOT . '/includes/json-encode.inc';
  return drupal_json_encode_helper($var);
}