diff --git a/www/admin/class_test.json.php b/www/admin/class_test.json.php index 6c596280..21906015 100644 --- a/www/admin/class_test.json.php +++ b/www/admin/class_test.json.php @@ -67,6 +67,8 @@ print "J/S::E-JSON ERROR: " . $json_class::jsonGetLastError() . ": " . $json_cla $array = ['foo' => 'bar']; $output = Json::jsonConvertArrayTo($array); print "S::JSON: " . DgS::printAr($array) . " => " . $output . "
"; +$array = ['foo' => 'bar', 'sub' => ['other' => 'this', 'foo' => 'bar', 'set' => [12, 34, true]]]; +print "Pretty:
" . Json::jsonPrettyPrint($array) . "

"; print ""; diff --git a/www/lib/CoreLibs/Convert/Json.php b/www/lib/CoreLibs/Convert/Json.php index 7f885df4..356e5db3 100644 --- a/www/lib/CoreLibs/Convert/Json.php +++ b/www/lib/CoreLibs/Convert/Json.php @@ -119,6 +119,23 @@ class Json } return $return_string === true ? $json_error_string : self::$json_last_error; } + + /** + * wrapper to call convert array to json with pretty print + * + * @param array $data + * @return string + */ + public static function jsonPrettyPrint(array $data): string + { + return self::jsonConvertArrayTo( + $data, + JSON_PRETTY_PRINT | + JSON_UNESCAPED_LINE_TERMINATORS | + JSON_UNESCAPED_SLASHES | + JSON_UNESCAPED_UNICODE + ); + } } // __END__