PHP code example of stefna / json-pointer

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

    

stefna / json-pointer example snippets



$document = [
	"foo" => ["bar", "baz"],
	"qux" => "quux"
];

$document = new \JsonPointer\BasicDocument('test', $document);

var_dump($document->has('/foo'));

var_dump($document->has('/foo/bar'));

/* Results:

bool(true)
bool(false)

*/


$document = [
	"foo" => ["bar", "baz"],
	"qux" => "quux"
];

$document = new \JsonPointer\BasicDocument('test', $document);

var_dump($document->get('/foo'));

var_dump($document->get('/foo/bar'));

/* Result

array(2) {
  [0] =>
  string(3) "bar"
  [1] =>
  string(3) "baz"
}

Throws JSONPointer\Exceptions\Reference - Referenced element does not exist: bar 

*/