Skip to content

Commit

Permalink
Minor optimisations on isJson function
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Sep 30, 2024
1 parent c4ba59c commit 4bf84aa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Support/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 4bf84aa

Please sign in to comment.