Add jsonPrettyPrint for formatted JSON output
Can be used for any debug output when needed
This commit is contained in:
@@ -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 . "<br>";
|
||||
$array = ['foo' => 'bar', 'sub' => ['other' => 'this', 'foo' => 'bar', 'set' => [12, 34, true]]];
|
||||
print "Pretty: <pre>" . Json::jsonPrettyPrint($array) . "</pre><br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
|
||||
@@ -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<mixed> $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__
|
||||
|
||||
Reference in New Issue
Block a user