PHP code example of vishalshakya / json-handler

1. Go to this page and download the library: Download vishalshakya/json-handler 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/ */

    

vishalshakya / json-handler example snippets


use Vishalshakya\JsonHandler;

$data = ['name' => 'John Doe', 'age' => 25];

$jsonString = JsonHandler::encode($data);

echo $jsonString;

$jsonString = '{"name":"John Doe","age":25}';

$object = JsonHandler::decode($jsonString);

echo $object->name; // John Doe
echo $object->age;  // 25

$jsonString = '{"name":"John Doe","age":25}';

$array = JsonHandler::decode($jsonString, true);

echo $array['name']; // John Doe
echo $array['age'];  // 25