PHP code example of psx / json

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

    

psx / json example snippets




$document = Document::from(\json_decode(\file_get_contents('/test.json')));
// or
$document = Document::from(\json_decode('{"author": {"name": "foo"}}'));

// get a value through a json pointer
$name = $document->pointer('/author/name');

// compare whether this document is equal to another document
$document->equals(['foo' => 'bar']);

// apply patch operations on the document
$document->patch([
    (object) ['op' => 'add', 'path' => '/author/uri', 'value' => 'http://google.com'],
]);

// convert the document back to a json string
echo $document->toString();



use PSX\Json\RPC\Server;
use PSX\Json\RPC\Exception\MethodNotFoundException;

$server = new Server(function($method, $arguments){
    if ($method === 'sum') {
        return array_sum($arguments);
    } else {
        throw new MethodNotFoundException('Method not found');
    }
});

$return = $server->invoke(\json_decode(file_get_contents('php://input')));

header('Content-Type: application/json');
echo \json_encode($return, JSON_PRETTY_PRINT);