pretty json

This commit is contained in:
Sergio Álvarez 2021-04-19 13:48:39 +02:00
parent d3b21bba1c
commit 4414b6035a
1 changed files with 11 additions and 0 deletions

View File

@ -16,6 +16,7 @@ $buttons = [
'qprintdecode' => 'Qprint Decode',
'hash' => 'Hash',
'hex' => 'Hex',
'prettyjson' => 'Pretty JSON',
];
$str = $result = $_GET['str'] ?? '';
@ -89,6 +90,16 @@ if ($action == 'reset') {
} elseif ($action == 'qprintdecode') {
$result = quoted_printable_decode($str)?: $str;
$help = 'https://www.php.net/quoted_printable_decode';
} elseif ($action == 'prettyjson') {
$jd = json_decode($str);
if (JSON_ERROR_NONE !== json_last_error()) {
$result = 'Error: '. json_last_error_msg() ."\n\n". $str;
} else {
$result = json_encode($jd, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION);
}
$help = 'https://www.php.net/json';
}
?><!doctype html>