PHP code example of alexistm / simple-json-php

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

    

alexistm / simple-json-php example snippets




     \Simple\json;
    
    $json = new json();
  
    // Objects to send (fetched from the DB for example)
    $object = new stdClass();
    $object->LastLog = '123456789123456';
    $object->Password = 'Mypassword';
    $object->Dramatic = 'Cat';
    $object->Things = array(1,2,3);
    
    // Forge the JSON
    $json->data = $object;
    $json->user = AlexisTM;
    $json->status = 'online';
    
    // Send the JSON
    $json->send();

  $json->send(options);
  > {  ...  }

  $json->send_callback('myCallback', options);
  > myCallback({  ...  });

  $json->send_var('myVariable', options);
  > var myVariable = {  ...  };

JSON_HEX_TAG 
echo "Apos: ",    json_encode($a, JSON_HEX_APOS), "\n";
echo "Quot: ",    json_encode($a, JSON_HEX_QUOT), "\n";
echo "Amp: ",     json_encode($a, JSON_HEX_AMP), "\n";
echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\n";
echo "All: ",     json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE)
 
$json->send(JSON_HEX_APOS | JSON_UNESCAPED_UNICODE);

$jsonString = $json->make();