O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required