You are viewing documentation for an outdated version. It is no longer supported!
Json
The \Aedart\Utils\Json
component offers a few JSON utilities. Among such, it wraps PHP's native json_encode()
and json_decode()
.
Encoding and Decoding
Using the encode()
and decode()
methods, you ensure that if encoding fails, a JsonEncodingException
will be thrown.
use Aedart\Utils\Json;
$encoded = Json::encode([
'name' => 'Reilly',
'age' => 32
]);
// ------------------------------------------ //
$decoded = Json::decode('{"name":"Michele Rodriguez","age":4}');
Note
From PHP 7.3, json_encode()
and json_decode()
will natively support an option to throw an exception upon encoding errors. These wrapper methods will be adapted to use this native option in the future.