Skip to content

Commit

Permalink
Use PHP native json_validate in isJson function if available (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Sep 15, 2023
1 parent 555e8de commit bc5bd1d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/StrMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public function isJson()
return false;
}

if (function_exists('json_validate')) {
return json_validate($value);
}

try {
json_decode($value, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
Expand Down

0 comments on commit bc5bd1d

Please sign in to comment.