how to retrieve specific nested values from JSON response in PHP using Guzzle 7.3
I'm working through a tutorial and I've searched everywhere and can't find a clear answer. I'm working on a PHP application that uses Guzzle 7.3 to make API requests, and I'm having trouble accessing specific nested values from the JSON response. The API returns a complex JSON structure, but when I try to decode and access certain values, I end up with unexpected results. Here's the response I'm getting: ```json { "data": { "user": { "id": 1, "name": "John Doe", "posts": [ { "id": 101, "title": "Post One" }, { "id": 102, "title": "Post Two" } ] } } } ``` I'm trying to retrieve the title of the first post. Here's the code I've written: ```php $response = $client->request('GET', 'https://api.example.com/users/1'); $body = json_decode($response->getBody(), true); $title = $body['data']['user']['posts'][0]['title']; echo $title; ``` However, when I run this, I get a PHP notice: "Undefined index: posts". I verified that the API response contains the expected structure. I've also added behavior handling to check for the existence of keys: ```php if (isset($body['data']['user']['posts']) && isset($body['data']['user']['posts'][0]['title'])) { $title = $body['data']['user']['posts'][0]['title']; } else { echo 'Post title not found'; } ``` This still results in the same notice. I've tried using `json_last_error()` to check for errors but it returns `JSON_ERROR_NONE`. Am I missing something? Could there be an scenario with how Guzzle handles the response, or do I need to adjust my array access logic? Any insights would be greatly appreciated! I'm on Linux using the latest version of Php. I'd be grateful for any help. I'm developing on macOS with Php. Any advice would be much appreciated.