JSON encode body, add Content-Type header.

@param array $arrayToJsonify
@param array $headers
@return array
15144
protected function makeJSON(array $arrayToJsonify, array $headers): array
    {
        if (empty($headers['Content-Type'])) {
            $headers['Content-Type'] = 'application/json';
        }
        /** @var string $body */
        $body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
        return [$body, $headers];
    }
382774
public function json($method, $uri, array $data = [], array $headers = [])
    {
        $files = $this->extractFilesFromDataArray($data);

        $content = json_encode($data);

        $headers = array_merge([
            'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
            'CONTENT_TYPE' => 'application/json',
            'Accept' => 'application/json',
        ], $headers);

        $this->call(
            $method, $uri, [], [], $files, $this->transformHeadersToServerVars($headers), $content
        );

        return $this;
    }
590948
protected function prepareHeaders(array $headers)
    {
        $preparedHeaders = [];

        foreach ($headers as $strName => $varValue) {
            $preparedHeaders[] = $strName.': '.$varValue;
        }

        return $preparedHeaders;
    }
382891
public static function json($data = array(), $status = 200, array $headers = array())
	{
		if ($data instanceof ArrayableInterface)
		{
			$data = $data->toArray();
		}

		return new JsonResponse($data, $status, $headers);
	}
964756
public function addHeaders(array $headers = [])
    {
        $this->headers = [];
        if($headers != []) {
            foreach ($headers as $header) {
                $this->headers[] = $header;
            }
        }
        return $this;
    }
6481
protected static function setContentType($headers, $response)
    {
        if (isset($headers['Content-Type'])) {
            return $headers;
        }
        if (in_array($response->statusCode(), [204, 304])) {
            return $headers;
        }

        $whitelist = [
            'application/javascript', 'application/json', 'application/xml', 'application/rss+xml'
        ];

        $type = $response->type();
        $charset = $response->charset();

        $hasCharset = false;
        if ($charset && (strpos($type, 'text/') === 0 || in_array($type, $whitelist))) {
            $hasCharset = true;
        }

        $value = $type;
        if ($hasCharset) {
            $value = "{$type}; charset={$charset}";
        }
        $headers['Content-Type'] = $value;

        return $headers;
    }
56195
public function getJSON($url,$data,$headers)
    {

        $response = $this->get($url,$data,$headers);
        $response["response"] = json_encode($response["response"]); // Again decoding it back to JSON

        return $response;
    }
576278
public static function capture(array $headers = null)
    {
        $headers  = $headers ?? apache_request_headers();
        $captured = [];
        foreach ($headers as $name => $value) {
            $captured[strtolower($name)] = new Header($name, $value);
        }

        return $captured;
    }
1115370
public function headers(array $headers): HttpRequest
    {
        foreach ($headers as $name => $value) {
            $this->header($name, $value);
        }

        return $this;
    }
318363
private function fetchContentType(array $headers)
    {
        foreach ($headers as $header) {
            if ($this->contentType = self::getContentTypeMatchInHeader($header)) {
                return true;
            }
        }

        return false;
    }
234118
public function resourceJson($data = array(), $status = 200, array $headers = array())
  {
    $headers = array_merge($headers, $this->getRequestLimitHeader());
    $headers = array_merge($headers, $this->getConfig('headers'));

    return $this->getResponse()->resourceJson($data, $status, $headers);
  }
1351716
protected function parseHeaders($headersJson)
    {
        $parameters = [];
        $headers = json_decode($headersJson, true);

        if (!is_array($headers) || empty($headers)) {
            throw new \InvalidArgumentException('Not a valid header of JWT string passed for deserialization');
        }

        foreach ($headers as $name => $value) {
            $parameter = $this->headerParameterFactory->get($name);
            $parameter->setValue($value);
            $parameters[] = $parameter;
        }

        return  $parameters;
    }
1363172
public static function collectionJson($data = array(), $status = 200, array $headers = array())
  {
    $collection = new Collection($data);
    $etag = $collection->getEtags();

    if ( ! empty($etag)) {
      $headers['ETag'] = $etag;
    }

    unset($collection);

    return self::json($data, $status, $headers);
  }
357455
public function setHeaders(array $headers)
    {
        $this->headers = [];
        foreach ($headers as $name => $val) {
            $this->addHeader($name, $val);
        }
        return $this;
    }
109238
public function doAction($methodName, $payload, $httpHeaders)
    {
        $this->setHttpHeader($httpHeaders);
        self::$soapClient->__setSoapHeaders($this->getAuthHeader());
        $response = self::$soapClient->$methodName($payload);

        return json_encode($response);
    }
615000
protected function prepareHeaders(array $headers = array())
    {
        $preparedHeaders = '';

        foreach($headers as $field => $content)
        {
            $fieldComponents = explode('-', $field);
            array_walk($fieldComponents, function(&$fieldComponent) {
                $fieldComponent = ucfirst(strtolower($fieldComponent));
            });
            $field = implode('-', $fieldComponents);

            $preparedHeaders .= sprintf("%s: %s \r\n", $field, $content);
        }

        return $preparedHeaders;
    }
824224
public static function fromArray(array $headers)
    {
        $instance = new static();

        if (isset($headers["content-type"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_CONTENT_TYPE;
            $instance->contentType = $headers["content-type"];
            unset($headers["content-type"]);
        }

        if (isset($headers["content-encoding"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_CONTENT_ENCODING;
            $instance->contentEncoding = $headers["content-encoding"];
            unset($headers["content-encoding"]);
        }

        if (isset($headers["delivery-mode"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_DELIVERY_MODE;
            $instance->deliveryMode = $headers["delivery-mode"];
            unset($headers["delivery-mode"]);
        }

        if (isset($headers["priority"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_PRIORITY;
            $instance->priority = $headers["priority"];
            unset($headers["priority"]);
        }

        if (isset($headers["correlation-id"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_CORRELATION_ID;
            $instance->correlationId = $headers["correlation-id"];
            unset($headers["correlation-id"]);
        }

        if (isset($headers["reply-to"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_REPLY_TO;
            $instance->replyTo = $headers["reply-to"];
            unset($headers["reply-to"]);
        }

        if (isset($headers["expiration"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_EXPIRATION;
            $instance->expiration = $headers["expiration"];
            unset($headers["expiration"]);
        }

        if (isset($headers["message-id"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_MESSAGE_ID;
            $instance->messageId = $headers["message-id"];
            unset($headers["message-id"]);
        }

        if (isset($headers["timestamp"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_TIMESTAMP;
            $instance->timestamp = $headers["timestamp"];
            unset($headers["timestamp"]);
        }

        if (isset($headers["type"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_TYPE;
            $instance->typeHeader = $headers["type"];
            unset($headers["type"]);
        }

        if (isset($headers["user-id"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_USER_ID;
            $instance->userId = $headers["user-id"];
            unset($headers["user-id"]);
        }

        if (isset($headers["app-id"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_APP_ID;
            $instance->appId = $headers["app-id"];
            unset($headers["app-id"]);
        }

        if (isset($headers["cluster-id"])) {
            $instance->flags |= ContentHeaderFrame::FLAG_CLUSTER_ID;
            $instance->clusterId = $headers["cluster-id"];
            unset($headers["cluster-id"]);
        }

        if (!empty($headers)) {
            $instance->flags |= ContentHeaderFrame::FLAG_HEADERS;
            $instance->headers = $headers;
        }

        return $instance;
    }