From 4414b6035a69ff6347b8ab6070796340e8cf0f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Mon, 19 Apr 2021 13:48:39 +0200 Subject: [PATCH] pretty json --- index.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.php b/index.php index 9bd204e..a8ad91d 100644 --- a/index.php +++ b/index.php @@ -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'; + } ?>