markup / json
Json wrapper to provide a more robust Api (matching 7.3 where possible)
Installs: 28 810
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 6
Forks: 1
Open Issues: 1
Requires
- php: ^7.1
Requires (Dev)
- phpstan/phpstan-shim: @stable
- phpunit/phpunit: ^7
- slevomat/coding-standard: @stable
- squizlabs/php_codesniffer: @stable
This package is auto-updated.
Last update: 2024-10-10 07:08:22 UTC
README
Json wrapper to provide a more robust API matching PHP 7.3 with exceptions rather than errors.
The following json options are always used
- JSON_UNESCAPED_UNICODE
- JSON_BIGINT_AS_STRING
- JSON_THROW_ON_ERROR
Usage
try { $json = '{"a":1}'; $data = Encoder::decode($json); $json = Encoder::encode($data); } catch (\JsonException $exception) { echo $exception->getMessage(); // echoes "Syntax error" }
Reference
- https://wiki.php.net/rfc/json_throw_on_error
- https://ayesh.me/Upgrade-PHP-7.3#json-exceptions
- https://github.com/php/php-src/blob/master/ext/json/json.c#L257