JSON encoding and decoding that throws exceptions on failure
Thin wrapper around PHP's
json_decode() functions, which throws exceptions when an operation fails.
- PHP 7.0+
$ composer require daverandom/exceptional-json
\ExceptionJSON\decode() functions in exactly the same way as you would with
json_decode(). The only difference is that they will throw an exception if the operation fails.
json_try_decode() in the root namespace if they don't already exist, these are
simply aliases of their namespaced counterparts.
$encoded = \ExceptionJSON\encode($data); $decoded = \ExceptionJSON\decode($encoded);