PHP code example of estaheri / json

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

    

estaheri / json example snippets



// validate is a string json
$is_json = json::_is($string);
// json decode or encode string
$json_decode = json::_in($json_string);
$json_encode = json::_out($data);
// get or update a key/keys from a json string
$json_string = json::update($json_string,['firstName'=>'Will','lastName'=>'Smith']);
$first_name = json::get($json_string,'firstName');
$name = json::get($json_string,['firstName','lastName']);
// remove a key/keys from a json string
$json_string = json::remove($json_string,'firstName');
$json_string = json::remove($json_string,['lastName','age']);
// convert array or object or json string to these three types
$array = json::to_array($data);
$json = json::to_json($data);
$object = json::to_object($data);


$json_string='{"id": "1","firstName": "Tom","lastName": "Cruise"}';
####################################################
// using php itself
// update a key from json string
$decoded=json_decode($json_string);
$decoded->firstName='Will';
$decoded->lastName='Smith';
$json_string = json_encode($decoded);
####################################################
// using this library
// update a key from json string
$json_string = json::update($json_string,['firstName'=>'Will','lastName'=>'Smith']);