/** * Format a flat JSON string to make it more human-readable * * @param array $json JSON as an array * * @return string Indented version of the original JSON string */ public static function json_format($json, $pretty = false) { /* * No pretty print - easy part */ if (!$pretty) { return json_encode($json); } /* * Pretty print only works for PHP >= 5.4 * Home made pretty print otherwise */ if (phpversion() && phpversion() >= 5.4) { return json_encode($json, JSON_PRETTY_PRINT); } else { return RestoUtil::prettyPrintJsonString(json_encode($json)); } }