Future\Json
, (*1)
Provides features, added to json_encode since version 5.3.0, for version 5.3.0., (*2)
Reference
-
>=5.5.0 Third parameter $depth allow let you set the maximum depth., (*3)
-
>=5.4.0 Option JSON_PRETTY_PRINT let use whitespace in returned data to format it., (*4)
-
>=5.4.0 Option JSON_UNESCAPED_SLASHES let don't escape /., (*5)
-
>=5.4.0 Option JSON_UNESCAPED_UNICODE let encode multibyte Unicode characters literally (default is to escape as \uXXXX)., (*6)
-
>=5.3.3 Option JSON_NUMERIC_CHECK let you encode numeric strings as numbers., (*7)
Usage
$data = array('foo' => 'bar');
echo Future\Json::encode($data, JSON_PRETTY_PRINT);
echo Future\Json::encode($data, JSON_NUMERIC_CHECK);
echo Future\Json::encode($data, JSON_UNESCAPED_SLASHES);
echo Future\Json::encode($data, JSON_UNESCAPED_UNICODE);
echo Future\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo Future\Json::encode($data, null, 4);
Shortcut
If you dont like Namespace\Classname::staticMethod call, you can use shortcuts., (*8)
future_json_encode($data, JSON_UNESCAPED_UNICODE, 10);
Testing
If current version PHP allow to use features described above, then encoder will pass all arguments to native function instead., (*9)
Directory tests/ contains json files that were generated using native function in PHP 5.5.6., (*10)
You can run the unit tests just to be sure that you will get exactly the same result regardless of your system:, (*11)
$ composer install --dev
$ vendor/bin/phpunit tests/