Using JSONPath in your PHP application
Using JSONPath in your PHP application requires you to include the JSONPath PHP implementation available at https://code.google.com/p/jsonpath/, and parsing the JSON string to a PHP mixed object before applying the JSONPath path you want to extract data from with the jsonPath function.
Getting ready
You'll need to download jsonpath.php from code.google.com at https://code.google.com/p/jsonpath/ and include it in your application with the require_once instruction. You'll also need to ensure that your PHP implementation includes json_decode.
How to do it…
Here's a simple example:
<html>
<body>
<pre>
<?php
require_once('jsonpath.php');
$json = '…'; // from the introduction to this chapter
$object = json_decode($json);
$titles = jsonPath($object, "$..title");
print($titles);
?>
</pre>
</body>
</html>How it works…
The preceding code begins by requiring the PHP JSONPath implementation, which defines the jsonPath...