diff --git a/src/Guzzle/Http/Message/Response.php b/src/Guzzle/Http/Message/Response.php index 8c940234..30668263 100644 --- a/src/Guzzle/Http/Message/Response.php +++ b/src/Guzzle/Http/Message/Response.php @@ -911,7 +911,7 @@ class Response extends AbstractMessage /** * Parse the JSON response body and return an array * - * @return array + * @return array|string|int|bool|float * @throws RuntimeException if the response body is not in JSON format */ public function json() @@ -921,7 +921,7 @@ class Response extends AbstractMessage throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error()); } - return $data ?: array(); + return $data === null ? array() : $data; } /** diff --git a/tests/Guzzle/Tests/Http/Message/ResponseTest.php b/tests/Guzzle/Tests/Http/Message/ResponseTest.php index c0bd4852..9d108f79 100644 --- a/tests/Guzzle/Tests/Http/Message/ResponseTest.php +++ b/tests/Guzzle/Tests/Http/Message/ResponseTest.php @@ -832,7 +832,7 @@ class ResponseTest extends \Guzzle\Tests\GuzzleTestCase { $response = new Response(200, array(), '{"foo": "bar"}'); $this->assertEquals(array('foo' => 'bar'), $response->json()); - // Always return an array from the json method + // Return array when null is a service response $response = new Response(200); $this->assertEquals(array(), $response->json()); }