CoreFiles by mySites.guru
JsonConverter.php37 lines, 1,039 bytes, from Joomla_5.4.2-Stable-Full_Package.zip
Raw History Compare with 5.4.1
md5
14b76b69cc11f485324f8055dae64f3d
sha1
3267b096b859bb7426e6f75debf60a4600d0c76e
sha256
3b90958cb1555ca2352771c68ca708a7b9986580d118e5ade97eb550a5d96384
<?php

declare(strict_types=1);

namespace Jose\Component\Core\Util;

use InvalidArgumentException;
use Throwable;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final class JsonConverter
{
    public static function encode(mixed $payload): string
    {
        try {
            return json_encode($payload, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } catch (Throwable $throwable) {
            throw new InvalidArgumentException('Invalid content.', $throwable->getCode(), $throwable);
        }
    }

    public static function decode(string $payload): mixed
    {
        try {
            return json_decode(
                $payload,
                true,
                512,
                JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
            );
        } catch (Throwable $throwable) {
            throw new InvalidArgumentException('Unsupported input.', $throwable->getCode(), $throwable);
        }
    }
}

The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.