1. Go to this page and download the library: Download squidit/json-to-jsonpath 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/ */
squidit / json-to-jsonpath example snippets
declare(strict_types=1);
// Make sure composer autoload has been loaded
use SquidIT\Json\JsonToJsonPath;
$jsonString = '{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"sub-title": "Sword of Honour",
"price": 12.99
}
],
"bicycle": {
"manufacturer name": "honda",
"color": "red",
"price": 19.95
}
}
}';
$jsonToJsonPath = new JsonToJsonPath($jsonString);
$jsonPathList = $jsonToJsonPath->getPathList();
echo 'Pathlist: '.PHP_EOL;
print_r(array_keys($jsonPathList));
echo 'JsonPathExpression: '.PHP_EOL;
var_dump($jsonPathList[array_key_last($jsonPathList)]);