diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php index 32f2947b4be9..618b7c5ef21a 100644 --- a/lib/public/AppFramework/Http/JSONResponse.php +++ b/lib/public/AppFramework/Http/JSONResponse.php @@ -60,15 +60,21 @@ public function __construct($data=array(), $statusCode=Http::STATUS_OK) { /** * Returns the rendered json - * @return string the rendered json + * @return string|null the rendered json * @since 6.0.0 * @throws \Exception If data could not get encoded */ public function render() { - $response = json_encode($this->data, JSON_HEX_TAG); - if($response === false) { - throw new \Exception(sprintf('Could not json_encode due to invalid ' . - 'non UTF-8 characters in the array: %s', var_export($this->data, true))); + if ($this->getStatus() === Http::STATUS_NO_CONTENT + || $this->getStatus() === Http::STATUS_NOT_MODIFIED + ) { + $response = null; + } else { + $response = json_encode($this->data, JSON_HEX_TAG); + if ($response === false) { + throw new \Exception(sprintf('Could not json_encode due to invalid ' . + 'non UTF-8 characters in the array: %s', var_export($this->data, true))); + } } return $response;