Exception-based wrappers for json_encode and json_decode
- PHP >= 7.0
composer require digiaonline/json-helpers
<?php
$data = [
'foo' => 'bar'
];
try {
$json = \Digia\JsonHelpers\JsonEncoder::encode($data);
}
catch (\InvalidArgumentException $e) {
}
<?php
$json = '["foo":"bar"]';
try {
$data = \Digia\JsonHelpers\JsonDecoder::decode($data);
}
catch (\InvalidArgumentException $e) {
}
MIT