From 4bf84aa28a46609fe15d5a495259aed572f1335e Mon Sep 17 00:00:00 2001 From: indykoning <15870933+indykoning@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:15:23 +0200 Subject: [PATCH] Minor optimisations on isJson function --- src/Support/Json.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Support/Json.php b/src/Support/Json.php index 1c047c24..acc1db67 100644 --- a/src/Support/Json.php +++ b/src/Support/Json.php @@ -6,10 +6,11 @@ class Json { public static function isJson($value): bool { - if (is_array($value) || is_object($value)) { + if (is_array($value) || is_object($value) || (is_string($value) && !str_starts_with('[', $value) && !str_starts_with('{', $value))) { return false; } + // TODO: when dropping support for php8.2 implement https://www.php.net/manual/en/function.json-validate.php return is_array(json_decode($value, true)); } }