$json = '{"name": "John", "age": 30, "city": "New York"}'; $data = json_decode($json); // Access the name and age properties $name = JPath::get($data, '/name'); $age = JPath::get($data, '/age'); echo "Name: $name\nAge: $age"; // Output: Name: John, Age: 30
$json = '[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}, {"name": "Bob", "age": 40}]'; $data = json_decode($json); // Find all objects where age is greater than or equal to 30 $results = JPath::search($data, '//*[@age >= 30]'); print_r($results); // Output: Array([0] => stdClass Object([name] => John [age] => 30) [1] => stdClass Object([name] => Bob [age] => 40))The PHP JPath library is part of the Joomla! Framework, a PHP framework for building web applications.