PHP code example of royalcms / wrappers-php-json
1. Go to this page and download the library: Download royalcms/wrappers-php-json library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
royalcms / wrappers-php-json example snippets
use Tarampampam\Wrappers\Json;
Json::encode(['foo' => 'bar']); // {"foo":"bar"}
Json::encode(tmpfile()); // Throws an exception - value cannot be resource
Json::decode('{"foo":"bar"}'); // ['foo' => 'bar']
Json::decode('{"foo":"bar"}', false); // $object->foo === bar
Json::decode('{"foo":"ba'); // Throws an exception - wrong json string
Json::encode([], JSON_EMPTY_ARRAYS_TO_OBJECTS); // {}
Json::encode(['foo' => []], JSON_EMPTY_ARRAYS_TO_OBJECTS); // {"foo":{}}
Json::encode(['foo' => 'bar'], JSON_PRETTY_PRINT_2_SPACES);
// {
// "foo": "bar"
// }
shell
$ composer