Json.php 514 B

123456789101112131415161718192021222324
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Helpers;
  4. final readonly class Json
  5. {
  6. /**
  7. * @throws \JsonException
  8. */
  9. public static function encode(mixed $data, int $flags = 0): string
  10. {
  11. return json_encode($data, $flags | JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
  12. }
  13. /**
  14. * @throws \JsonException
  15. */
  16. public static function decode(string $json, int $flags = 0): mixed
  17. {
  18. return json_decode($json, true, flags: $flags | JSON_THROW_ON_ERROR);
  19. }
  20. }