PHP code example of hgg / json

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

    

hgg / json example snippets




$data = array(
    'field' => 'value'
);

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



$data = Json::decode($jsonString, true);



$data = Json::decode($path, true);



$prettyJson = Json::prettyPrint($data);



$invalidJson = '{';

try {
    $data = Json::decode($invalidJson);
} catch (HGG\Json\Exception\RuntimeException $e) {
    printf("Error message: %s\n", $e->getMessage());
    printf("Error code: %d\n", $e->getCode());
}