decode($data); } else { //Not json, return as string return $data; } } else { //No content headers, assume json return $this->decode($data); } } /** * @param string|null $data * * @return array * @throws JsonErrorException */ private function decode(?string $data): array { if ($data === null || strlen($data) === 0) { return []; } try { return json_decode($data, true, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new JsonErrorException($e->getCode(), $data, []); } } }