3 final class PhabricatorConfigJSON
extends Phobject
{
5 * Properly format a JSON value.
7 * @param wild Any value, but should be a raw value, not a string of JSON.
10 public static function prettyPrintJSON($value) {
11 // If the value is an array with keys "0, 1, 2, ..." then we want to
13 // If the value is an array with other keys, we want to show it as an
15 // Otherwise, just use the default encoder.
18 if (is_array($value)) {
19 $list_keys = range(0, count($value) - 1);
20 $actual_keys = array_keys($value);
22 if ($actual_keys === $list_keys) {
31 $result = id(new PhutilJSON())->encodeAsList($value);
34 $result = id(new PhutilJSON())->encodeFormatted($value);
37 $result = json_encode($value);
41 // For readability, unescape forward slashes. These are normally escaped
42 // to prevent the string "</script>" from appearing in a JSON literal,
43 // but it's irrelevant here and makes reading paths more difficult than
45 $result = str_replace('\\/', '/', $result);