W3docs

Guzzle 6: no more json() method for responses

In Guzzle 6, the json() method for parsing JSON responses has been removed.

In Guzzle 6, the json() method for parsing JSON responses has been removed. Instead, you can use the getBody() method to retrieve the response body as a PSR-7 StreamInterface, and then use the json_decode() function in PHP to parse the JSON.

For example:

Example of using getContents() to parse JSON responses in Guzzle 6

$response = $client->request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
$data = json_decode($response->getBody()->getContents(), true);

Alternatively, you can explicitly cast the stream to a string:

$response = $client->request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
$data = json_decode((string) $response->getBody(), true);

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

This change was made to improve flexibility and allow for more fine-grained control over how responses are handled.